kreuzwerker/terraform-provider-docker

"One-shot tasks" via `docker_container` fail with "Error: No such container: xxx"

ZauberNerd opened this issue ยท 0 comments

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and docker Provider) Version

Terraform v1.9.2
on linux_amd64
+ provider registry.terraform.io/kreuzwerker/docker v3.0.2

Affected Resource(s)

  • docker_container

Terraform Configuration Files

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.2"
    }
  }
}

provider "docker" {}

resource "docker_container" "build-task" {
  image    = "debian:testing"
  name     = "example-build-task"
  # imagine this being a build process on a bind-mounted volume
  command  = ["echo", "hello world"]
  # we want to wait for the build to finish (e.g. to be able to use depends_on)
  attach   = true
  # the build (and thus the container) will finish at some point
  must_run = false
  # we want to clean-up and remove the build container
  rm       = true
}

Debug Output

https://gist.github.com/ZauberNerd/3245880f47e969baffeb0aa58ed2f31c

Panic Output

Expected Behaviour

terraform apply should not fail.

Actual Behaviour

terraform apply fails.

Steps to Reproduce

  1. terraform apply

Important Factoids

The debug log was captured by running terraform in docker (with the hosts docker socket mounted), because I have installed OpenTofu instead of terraform on my host.
But the error occurs with both terraform and opentofu.

References

  • #0000

Workaround

I'm using the local-exec provisioner for now (docker run --rm ...).