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

Unable to remove Docker image: image is referenced in multiple repositories #46

Open
mavogel opened this issue Dec 25, 2020 · 7 comments
Labels
bug Something isn't working pinned r/image Relates to the image resource

Comments

@mavogel
Copy link
Contributor

mavogel commented Dec 25, 2020

This issue was originally opened by @stoically as hashicorp/terraform-provider-docker#301. It was migrated here as a result of the community provider takeover from @kreuzwerker. The original body of the issue is below.


Terraform Version

Terraform v0.13.3

Affected Resource(s)

  • docker_image

Terraform Configuration Files

data "docker_registry_image" "traefik" {
  name = "traefik:latest"
}

resource "docker_image" "traefik" {
  name          = data.docker_registry_image.traefik.name
  pull_triggers = [data.docker_registry_image.traefik.sha256_digest]
}

Expected Behavior

Should always silently upgrade the image / container

Actual Behavior

Error: Unable to remove Docker image: Error response from daemon: conflict: unable to delete 1a3f0281f41e (must be forced) - image is referenced in multiple repositories

Steps to Reproduce

Unfortunately not sure how to reproduce

Notes

Would it be safe to always force-remove images?

@suzuki-shunsuke suzuki-shunsuke added the r/image Relates to the image resource label Dec 28, 2020
@suzuki-shunsuke
Copy link
Collaborator

I think we should ignore the failure to remove Docker images because images can be referenced out of Terraform.

@suzuki-shunsuke suzuki-shunsuke added the bug Something isn't working label Dec 28, 2020
@suzuki-shunsuke
Copy link
Collaborator

#104 may solve this issue.

@mavogel mavogel linked a pull request Dec 29, 2020 that will close this issue
@mavogel mavogel added this to the v2.10.0 milestone Dec 29, 2020
@mavogel
Copy link
Contributor Author

mavogel commented Dec 29, 2020

I think it will partially solve it. Here the case is that the user would like to update the latest tag always

@mavogel mavogel removed this from the v2.10.0 milestone Jan 8, 2021
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Mar 29, 2021
@github-actions github-actions bot closed this as completed Apr 6, 2021
@mavogel mavogel removed the stale label Apr 7, 2021
@mavogel mavogel reopened this Apr 7, 2021
@github-actions
Copy link

github-actions bot commented Jun 6, 2021

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Jun 6, 2021
@mavogel mavogel added pinned and removed stale labels Jun 14, 2021
@dubo-dubon-duponey
Copy link
Contributor

This is still a problem with 2.15.0.

If two containers are spun from the same image, a subsequent run where the image should be updated will stop one container, try to update the image and fail because the other container is still running.

This doesn't feel right. If two containers depend on the same image, they should both be destroyed before the image (not familiar with the internals here, but I assume it's a graph of dependencies).

@zeddD1abl0
Copy link

If I may posit a solution:

  1. Always download the latest image
  2. Update all the Terraform-referenced Docker containers to the new image
  3. Attempt to remove the older image.

A failure to remove the older image at this point may be seen as a Warning, not a Failure, as Terraform has technically completed its proper procedure and updated to the latest available image for all the containers in the list.


BTW, this can be easily replicated by doing the following:

#MariaDB Registry Image
data "docker_registry_image" "mariadb" {
  name = "mariadb:latest"
}

#Maria DB Docker Image
resource "docker_image" "mariadb" {
  name          = data.docker_registry_image.mariadb.name
  pull_triggers = [data.docker_registry_image.mariadb.sha256_digest]
  keep_locally  = false
}

#Maria DB Docker Image
resource "docker_image" "mariadb_another" {
  name          = data.docker_registry_image.mariadb.name
  pull_triggers = [data.docker_registry_image.mariadb.sha256_digest]
  keep_locally  = false
}

If you deploy both those images, when Terraform goes to update mariadb, sometimes it will fail and complain that it can't remove the image. It will also fail to update the image for mariadb_another, leaving your MariaDB instances out of sync. It's never been a big issue for me, because if I get annoyed by it, I just destroy everything and let Terraform rebuild it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned r/image Relates to the image resource
Projects
None yet
Development

No branches or pull requests

4 participants