Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Impossible to delete docker-devcontainer workspaces when 1+ other workspaces are running. #15972

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

Closed
phorcys420 opened this issue Dec 29, 2024 · 5 comments · Fixed by #16012
Closed
Labels
need-help Assign this label prompts an engineer to check the issue. Only humans may set this. s2 Broken use cases or features (with a workaround). Only humans may set this.

Comments

@phorcys420
Copy link
Member

phorcys420 commented Dec 29, 2024

(Discord discussion)


When multiple docker-devcontainer workspaces are running, deleting one of them will trigger the following issue:

Terraform 1.9.8
coder_agent.main: Plan to delete
docker_volume.workspaces: Plan to delete
docker_image.devcontainer_builder_image: Plan to delete
coder_agent.main: Destroying... [id=d87332f6-93ab-420d-bf3d-5818bc0fc18c]
coder_agent.main: Destruction complete after 0s
docker_volume.workspaces: Destroying... [id=coder-aee29e12-d241-40e5-a075-f617b500a947]
docker_image.devcontainer_builder_image: Destroying... [id=sha256:0043aade3996c429a302de5f79050c63bf2a56a7286c5aef2cd65387bc870db5ghcr.io/coder/envbuilder:latest]
docker_image.devcontainer_builder_image: Destruction errored after 1s
docker_volume.workspaces: Destruction complete after 3s
Error: Unable to remove Docker image: Error response from daemon: conflict: unable to remove repository reference "ghcr.io/coder/envbuilder:latest" (must force) - container 7e439682639e is using its referenced image 0043aade3996

This is due to the fact that deleting a workspace will try to delete all of its resources, except the envbuilder image is shared between all the workspaces of that same template, which will make any workspace deletion fail.

Possible workaround

This could be fixed by adding the lifecycle.prevent_destroy attribute to the docker_image resource:

resource "docker_image" "devcontainer_builder_image" {
  name = local.devcontainer_builder_image

+  lifecycle {
+    prevent_destroy = true
+  }
}

But then you'll run into this issue when deleting the workspace:

Error: Instance cannot be destroyed
on main.tf line 156:
  156: resource "docker_image" "devcontainer_builder_image" {
Resource docker_image.devcontainer_builder_image has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or reduce the scope of the plan using the -target option.
@phorcys420 phorcys420 added the need-help Assign this label prompts an engineer to check the issue. Only humans may set this. label Dec 29, 2024
@coder-labeler coder-labeler bot added the needs-triage Issue that require triage label Dec 29, 2024
@matifali
Copy link
Member

I have run into it multiple times. This is mostly a terraform thing rather than a Coder or builder issue.

@matifali matifali added s2 Broken use cases or features (with a workaround). Only humans may set this. and removed needs-triage Issue that require triage labels Dec 30, 2024
@johnstcn
Copy link
Member

johnstcn commented Jan 2, 2025

@ChristopherJTrent
Copy link
Contributor

what about keep_locally = true?

https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/image#keep_locally-1

I apologize if I am chiming in out of turn here. I'm one of the original users who reported this on discord in the above linked discussion.
I went ahead and tested this on my own instance.

Setting keep_locally did remedy the issue of not being able to delete workspaces. I can't speak authoritatively to any other side-effects, but I can say anecdotally that it doesn't appear that this change is causing any significant increase in storage usage.

@johnstcn
Copy link
Member

johnstcn commented Jan 2, 2025

Thanks @ChristopherJTrent ! I went ahead and made a PR to update the example templates.

@phorcys420
Copy link
Member Author

Nice! thanks @johnstcn @ChristopherJTrent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-help Assign this label prompts an engineer to check the issue. Only humans may set this. s2 Broken use cases or features (with a workaround). Only humans may set this.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants