Skip to content

Error response from daemon: Conflict. The container name "/<container_name>" is already in use by container "xxxx". You have to remove (or rename) that container to be able to reuse that name!

0

I have a Greengrass component with a lifecycle like below:

"Lifecycle": {
  "run": "docker compose -f {artifacts:path}/docker-compose.yml up"
}

However, when i deploy the component again, sometimes it encounters the error:

Error response from daemon: Conflict. The container name "/<container_name>" is already in use by container "xxxx". You have to remove (or rename) that container to be able to reuse that name!

I attempt to add the Shutdown lifecycle

"Lifecycle": {
  "run": "docker compose -f {artifacts:path}/docker-compose.yml up",
  "shutdown": "docker compose -f {artifacts:path}/docker-compose.yml rm -sf"
}

However the shutdown lifecycle also removes the images, which is not my intension. How to make the deployment removes the container only during shutdown of the component?

asked 2 years ago598 views
1 Answer
0

Instead, you can use the docker compose down command in the shutdown lifecycle, which stops and removes containers, but does not remove the images. Here’s how you can modify your lifecycle:

"Lifecycle": {
  "run": "docker compose -f {artifacts:path}/docker-compose.yml up",
  "shutdown": "docker compose -f {artifacts:path}/docker-compose.yml down"
}

This way, when the component is shut down, the Docker containers will be removed, but the images will be kept intact. When you deploy the component again, it will not conflict with the existing containers.

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.