GithubHelp home page GithubHelp logo

Comments (1)

lkwg82 avatar lkwg82 commented on July 26, 2024 1

For next time, please add version of terraform, use syntax highlighting it really helps to read code an minify the potential bug example.

TLDR
usage bug and maybe non defensive implementation of missing health check in provider

Longer

I could reproduce the behaviour, but it starts with the config of your example.

The example tries to start a container python:latest and should wait for a healthy state.

See

If true, then the Docker container is waited for being healthy state after creation. If false, then the container health state is not checked. Defaults to false.
https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container#wait

Lets have a look at the healthcheck in the image (executed by the container):

$ docker history python:latest
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
fc7a60e86bae   4 weeks ago   CMD ["python3"]                                 0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   RUN /bin/sh -c set -eux;   wget -O get-pip.p…   10.1MB    buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV PYTHON_GET_PIP_SHA256=9cc01665956d22b3bf…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV PYTHON_GET_PIP_URL=https://github.com/py…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV PYTHON_PIP_VERSION=23.2.1                   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   RUN /bin/sh -c set -eux;  for src in idle3 p…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   RUN /bin/sh -c set -eux;   wget -O python.ta…   60.7MB    buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV PYTHON_VERSION=3.12.1                       0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV GPG_KEY=7169605F62C751356D054A26A821E680…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   RUN /bin/sh -c set -eux;  apt-get update;  a…   18.6MB    buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV LANG=C.UTF-8                                0B        buildkit.dockerfile.v0
<missing>      4 weeks ago   ENV PATH=/usr/local/bin:/usr/local/sbin:/usr…   0B        buildkit.dockerfile.v0
<missing>      2 weeks ago   /bin/sh -c set -ex;  apt-get update;  apt-ge…   587MB     
<missing>      2 weeks ago   /bin/sh -c apt-get update && apt-get install…   177MB     
<missing>      2 weeks ago   /bin/sh -c set -eux;  apt-get update;  apt-g…   48.4MB    
<missing>      2 weeks ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      2 weeks ago   /bin/sh -c #(nop) ADD file:7d8adf68670e8dc2a…   116MB

No healthcheck as it would be implemented it according to https://docs.docker.com/engine/reference/builder/#healthcheck

So lets recheck it with a proper healthcheck:

main.tf

resource "docker_image" "ubuntu" {
  name = "python:latest"
  keep_locally = true # convinience for iterations
}

resource "docker_container" "container" {
  image = docker_image.ubuntu.image_id
  name  = "ubuntu1e-${replace(timestamp(),":","")}" # unique name for iterations
  wait  = true
 
  tty = true # need to use interactive container, very unusual
  healthcheck {
    interval = "1s"
    start_period = "1s"
    retries = 1
    test = [ "CMD", "/bin/true"]
  }
}

this results in no crash with this output:

Terraform will perform the following actions:

  # docker_container.container will be created
  + resource "docker_container" "container" {
      + attach                                      = false
      + bridge                                      = (known after apply)
      + command                                     = (known after apply)
      + container_logs                              = (known after apply)
      + container_read_refresh_timeout_milliseconds = 15000
      + entrypoint                                  = (known after apply)
      + env                                         = (known after apply)
      + exit_code                                   = (known after apply)
      + hostname                                    = (known after apply)
      + id                                          = (known after apply)
      + image                                       = "sha256:fc7a60e86baeb42215d3f91f262880a3a9b4efd00c91f6597e65d9e1c7745ec9"
      + init                                        = (known after apply)
      + ipc_mode                                    = (known after apply)
      + log_driver                                  = (known after apply)
      + logs                                        = false
      + must_run                                    = true
      + name                                        = (known after apply)
      + network_data                                = (known after apply)
      + read_only                                   = false
      + remove_volumes                              = true
      + restart                                     = "no"
      + rm                                          = false
      + runtime                                     = (known after apply)
      + security_opts                               = (known after apply)
      + shm_size                                    = (known after apply)
      + start                                       = true
      + stdin_open                                  = false
      + stop_signal                                 = (known after apply)
      + stop_timeout                                = (known after apply)
      + tty                                         = true
      + wait                                        = true
      + wait_timeout                                = 60

      + healthcheck {
          + interval     = "1s"
          + retries      = 1
          + start_period = "1s"
          + test         = [
              + "CMD",
              + "/bin/true",
            ]
          + timeout      = "0s"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
docker_container.container: Creating...
docker_container.container: Creation complete after 2s [id=77a986cccd6e1b9ee952f411f7ae901510f3869cb5bd2c9224fea3e53f1caab2]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

IMHO: no one would use an interactive container u did, this is bleeding edge or hacking around ;).

from terraform-provider-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.