terraform-provider-docker icon indicating copy to clipboard operation
terraform-provider-docker copied to clipboard

Error: container exited immediately

Open reeshabhranjan opened this issue 1 year ago • 1 comments

Terraform (and docker Provider) Version

Terraform: v1.2.5 Docker Provider: v2.20.0

Affected Resource(s)

  • docker_container

Terraform Configuration Files

This is the example available in README.md.

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "2.20.0"
    }
  }
}

provider "docker" {
  host = "unix:///var/run/docker.sock"
}

# Pulls the image
resource "docker_image" "ubuntu" {
  name = "ubuntu:latest"
}

# Create a container
resource "docker_container" "foo" {
  image = docker_image.ubuntu.latest
  name  = "foo"
}

Debug Output

https://gist.github.com/reeshabhranjan/11fc46d55a246305052b9ea73dec51ab

Panic Output

Expected Behaviour

An Ubuntu container should have been setup on my PC and the terraform process should have exited normally.

Actual Behaviour

An Ubuntu container was not created on my PC and the terraform process exited with an error code.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000

reeshabhranjan avatar Aug 10 '22 21:08 reeshabhranjan

Try setting must_run = false in docker_container.foo

giesmininkas avatar Aug 16 '22 14:08 giesmininkas

The behaviour is expected and not an issue with the provider itself. The terraform code of yours is an equivalent to running docker run ubuntu. This command also exits immediately since we did not provide any command to run. Please use the command attribute to specify a command to run.

Or you use must _run = false to get rid of the error message (but then you still won't have a running container, as it exits immediately without a proper command)

Junkern avatar Aug 29 '22 10:08 Junkern