Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: on port change, docker provider attempts to create before destroying container #1356

Open
kumavis opened this issue Feb 7, 2025 · 1 comment
Labels
awaiting-feedback Blocked on input from the author kind/bug Some behavior is incorrect or out of spec

Comments

@kumavis
Copy link

kumavis commented Feb 7, 2025

Describe what happened

pulumi docker provider attempted to create the new container before deleting the old one

Sample program

define a container for grafana and deploy, update the port field

Log output

pulumi-greenthumb on  main [!?] via  v20.18.0 via  greenthumb took 17s 
❯ pulumi up
Previewing update (greenthumb):
     Type                       Name                     Plan        Info
     pulumi:pulumi:Stack        learn-pulumi-greenthumb              
 +-  └─ docker:index:Container  grafana                  replace     [diff: ~ports]

Resources:
    +-1 to replace
    33 unchanged

Do you want to perform this update? details
  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:greenthumb::learn-pulumi::pulumi:pulumi:Stack::learn-pulumi-greenthumb]
    ++docker:index/container:Container: (create-replacement)
        [id=35dafe4b10d1be57dc833c54ffdd066c92db316053aae7c97b6c06b27cc8533c]
        [urn=urn:pulumi:greenthumb::learn-pulumi::docker:index/container:Container::grafana]
        [provider=urn:pulumi:greenthumb::learn-pulumi::pulumi:providers:docker::docker::bc62b34d-2c62-4995-8c81-872aceeee3df]
      ~ ports: [
          - [0]: {
                  - external: 32858
                  - internal: 3000
                  - ip      : "0.0.0.0"
                  - protocol: "tcp"
                }
        ]
    +-docker:index/container:Container: (replace)
        [id=35dafe4b10d1be57dc833c54ffdd066c92db316053aae7c97b6c06b27cc8533c]
        [urn=urn:pulumi:greenthumb::learn-pulumi::docker:index/container:Container::grafana]
        [provider=urn:pulumi:greenthumb::learn-pulumi::pulumi:providers:docker::docker::bc62b34d-2c62-4995-8c81-872aceeee3df]
      ~ ports: [
          - [0]: {
                  - external: 32858
                  - internal: 3000
                  - ip      : "0.0.0.0"
                  - protocol: "tcp"
                }
        ]
    --docker:index/container:Container: (delete-replaced)
        [id=35dafe4b10d1be57dc833c54ffdd066c92db316053aae7c97b6c06b27cc8533c]
        [urn=urn:pulumi:greenthumb::learn-pulumi::docker:index/container:Container::grafana]
        [provider=urn:pulumi:greenthumb::learn-pulumi::pulumi:providers:docker::docker::bc62b34d-2c62-4995-8c81-872aceeee3df]

Do you want to perform this update? yes
Updating (greenthumb):
     Type                       Name                     Status                  Info
     pulumi:pulumi:Stack        learn-pulumi-greenthumb  **failed**              1 error
 ++  └─ docker:index:Container  grafana                  **creating failed**     [diff: ~ports]; 2 errors

Diagnostics:
  docker:index:Container (grafana):
    error:   sdk-v2/provider2.go:515: sdk.helper_schema: Unable to create container: Error response from daemon: Conflict. The container name "/grafana" is already in use by container "35dafe4b10d1be57dc833c54ffdd066c92db316053aae7c97b6c06b27cc8533c". You have to remove (or rename) that container to be able to reuse that name.: [email protected]
    error: 1 error occurred:
    	* Unable to create container: Error response from daemon: Conflict. The container name "/grafana" is already in use by container "35dafe4b10d1be57dc833c54ffdd066c92db316053aae7c97b6c06b27cc8533c". You have to remove (or rename) that container to be able to reuse that name.

  pulumi:pulumi:Stack (learn-pulumi-greenthumb):
    error: update failed

Affected Resource(s)

docker provider, container

Output of pulumi about

❯ pulumi about
CLI          
Version      3.147.0
Go Version   go1.23.5
Go Compiler  gc

Host     
OS       darwin
Version  15.2
Arch     arm64

Plugins
KIND      NAME          VERSION
resource  command       0.0.1-testwindows.signing
resource  digitalocean  4.38.0
resource  docker        4.6.1
resource  local         0.1.6
language  nodejs        3.147.0
resource  tls           5.1.0

pulumi:pulumi:Stack                                           urn:pulumi:greenthumb::learn-pulumi::pulumi:pulumi:Stack::learn-pulumi-greenthumb
[...snip...]
command:remote:Command                                        urn:pulumi:greenthumb::learn-pulumi::command:remote:Command::prep-grafana-config
command:remote:CopyToRemote                                   urn:pulumi:greenthumb::learn-pulumi::command:remote:CopyToRemote::grafana-config
docker:index/remoteImage:RemoteImage                          urn:pulumi:greenthumb::learn-pulumi::docker:index/remoteImage:RemoteImage::grafana
docker:index/container:Container                              urn:pulumi:greenthumb::learn-pulumi::docker:index/container:Container::grafana

Dependencies:
NAME                  VERSION
@pulumi/docker        4.6.1
@pulumi/local         0.1.6
@pulumi/pulumi        3.147.0
@pulumi/tls           5.1.0
@types/node           18.19.74
typescript            5.7.3
@pulumi/command       0.0.1-testwindows.signing
@pulumi/digitalocean  4.38.0

Additional context

the grafana container named in the error "already exosts" is the same one associated with the stack, 35dafe4b10d1

root@greenthumb-primary:~# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                                          NAMES
[...snip...]
35dafe4b10d1   3344a121f449   "/run.sh"                17 minutes ago   Up 17 minutes   0.0.0.0:32858->3000/tcp                                                        grafana

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@kumavis kumavis added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Feb 7, 2025
@rquitales
Copy link
Member

Thanks for reporting this issue.

A workaround for now would be to set the delete BeforeReplace config option on the resource to true. Ref: https://www.pulumi.com/docs/iac/concepts/options/deletebeforereplace/.

This will ensure the resource will be deleted first, before creating the replacement. Note, the default Pulumi behaviour is to create the replacement resource first, to minimize downtime.

@rquitales rquitales added awaiting-feedback Blocked on input from the author and removed needs-triage Needs attention from the triage team labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-feedback Blocked on input from the author kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants