Hi! I have a block resource “docker_container”
resource "docker_container" "example-alpine" {
lifecycle {
create_before_destroy = true
}
image = docker_image.example-alpine.latest
name = "site"
restart = "always"
privileged = "true"
ports {
internal = 80
external = 8891
}
I want to use the lifecycle meta-Argument create_before_destroy = true
when i next run the command terraform apply to replace the container imperceptibly with new version docker image.
But I have an issue when I run commands terraform apply
docker_container.example-alpine: Creating...
╷
│ Error: Unable to create container: Error response from daemon: Conflict. The container name "/site" is already in use by container "450b17cdb435af240aba742b552c36b315880723a9e0bc252296393a0c47bbd2". You have to remove (or rename) that container to be able to reuse that name.
or
docker_container.example-alpine: Creating...
╷
│ Error: Unable to start container: Error response from daemon: driver failed programming external connectivity on endpoint trusting_chandrasekhar (ec793752c675d109323e606cee97cde2d1f355338f8d95012d1e918e058fb819): Bind for 0.0.0.0:8891 failed: port is already allocated
Is it possible to run new docker container without destroy previous container?