GithubHelp home page GithubHelp logo

Comments (2)

suzuki-shunsuke avatar suzuki-shunsuke commented on August 30, 2024

Thank you for your report.
But I can't reproduce the issue.

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "2.8.0"
    }
  }
}

variable "image" {
  default = "alpine:3.11.6"
}

variable "discord_token" {
  description = "Discord auth token"
}

provider "docker" {
}

resource "docker_container" "wbld" {
  name    = "wbld"
  image   = docker_image.wbld.latest
  command = ["tail", "-f", "/dev/null"]
  env     = ["DISCORD_TOKEN=${var.discord_token}"]

  volumes {
    volume_name    = "wbld_platformio"
    container_path = "/root/.platformio"
  }

  volumes {
    volume_name    = "wbld_buildcache"
    container_path = "/root/.buildcache"
  }
}

data "docker_registry_image" "wbld" {
  name = var.image
}

resource "docker_image" "wbld" {
  name          = data.docker_registry_image.wbld.name
  pull_triggers = [data.docker_registry_image.wbld.sha256_digest]
  keep_locally  = true
}
$ terraform version
Terraform v0.14.2
+ provider registry.terraform.io/kreuzwerker/docker v2.8.0

$ terraform apply -auto-approve
docker_image.wbld: Creating...
docker_image.wbld: Creation complete after 1s [id=sha256:f70734b6a266dcb5f44c383274821207885b549b75c8e119404917a61335981aalpine:3.11.6]
docker_container.wbld: Creating...
docker_container.wbld: Creation complete after 1s [id=0dc5b981ca697b87e6028a293f9ecd984042c71f7980dd95a6481f7600d656cd]

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

$ terraform destroy -auto-approve
docker_container.wbld: Destroying... [id=0dc5b981ca697b87e6028a293f9ecd984042c71f7980dd95a6481f7600d656cd]
docker_container.wbld: Destruction complete after 0s
docker_image.wbld: Destroying... [id=sha256:f70734b6a266dcb5f44c383274821207885b549b75c8e119404917a61335981aalpine:3.11.6]
docker_image.wbld: Destruction complete after 0s

Destroy complete! Resources: 2 destroyed.

$ docker images alpine:3.11.6
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              3.11.6              f70734b6a266        7 months ago        5.61MB

It succeeds to run terraform destroy and the Docker image isn't removed.

On the other hand, if keep_locally is false, it failed to remove the Docker image, which means the provider tried to remove the Docker image as expected.

$ terraform destroy -auto-approve
docker_container.wbld: Destroying... [id=09682e5ba28f377f25b39ff3e9e99257daa5acf781434a98820e768b83601793]
docker_container.wbld: Destruction complete after 0s
docker_image.wbld: Destroying... [id=sha256:f70734b6a266dcb5f44c383274821207885b549b75c8e119404917a61335981aalpine:3.11.6]

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

I checked the source code and it seems that the Docker image isn't removed if keep_locally is true.

from terraform-provider-docker.

andyshinn avatar andyshinn commented on August 30, 2024

Thanks. I think the error may actually be elsewhere. Sorry for false alarm.

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.