hashicorp / terraform-provider-docker

As part of our introduction to self-service publishing in the Terraform Registry, this copy of the provider has been archived, and ownership has been transferred to active maintainers in the community. Please see the new location on the Terraform Registry: https://registry.terraform.io/providers/kreuzwerker/docker/latest
https://registry.terraform.io/providers/kreuzwerker/docker/latest
Mozilla Public License 2.0
132 stars 91 forks source link

Failed Docker container creation shouldn't destroy container afterwards #225

Open ghost opened 5 years ago

ghost commented 5 years ago

This issue was originally opened by @cadavre as hashicorp/terraform#23430. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.16
+ provider.docker v2.5.0

Terraform Configuration Files

resource "docker_network" "nginx-proxy" {
  name = "nginx-proxy"
}

resource "docker_image" "nginx-proxy" {
  name = "jwilder/nginx-proxy:latest"
}

resource "docker_container" "nginx-proxy" {
  image = docker_image.nginx-proxy.latest
  name  = "nginx-proxy"
  networks_advanced {
    name = docker_network.nginx-proxy.name
  }
  ports {
    internal = 80
    external = 81
  }
}

Debug Output

After running plan:

  # docker_container.nginx-proxy will be created
  + resource "docker_container" "nginx-proxy" {
      + attach           = false
      + bridge           = (known after apply)
      + container_logs   = (known after apply)
      + exit_code        = (known after apply)
      + gateway          = (known after apply)
      + id               = (known after apply)
      + image            = "sha256:d1c0beda680464dca3db4551ad458f8ee19fd4098d3c84c21bfa349634e7d53c"
      + ip_address       = (known after apply)
      + ip_prefix_length = (known after apply)
      + log_driver       = "json-file"
      + logs             = false
      + must_run         = true
      + name             = "nginx-proxy"
      + network_data     = (known after apply)
      + restart          = "no"
      + rm               = false
      + start            = true

      + networks_advanced {
          + aliases = []
          + name    = "nginx-proxy"
        }

      + ports {
          + external = 81
          + internal = 80
          + ip       = "0.0.0.0"
          + protocol = "tcp"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Crash Output

After running apply:

docker_container.nginx-proxy: Creating...

Error: Container 1ecb33574b999d0639a6f8b6826370719669cbe991293835124f3a36b745871f exited after creation, error was: 

  on docker.tf line 9, in resource "docker_container" "nginx-proxy":
   9: resource "docker_container" "nginx-proxy" {

Expected Behavior

  1. Terraform should show logs from launching the container.
  2. Docker container should not be destroyed after fail.

Actual Behavior

  1. No logs appear.
  2. Container is destroyed so logs cannot be accessed via docker logs.

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional info

attach = true
logs   = true

Gives same output as with their defaults.