Docker-Compose Issue with container name

I created a docker image with the necessary packages. I launched the docker image, specifying the host and guest port along with the required volume mounting Example:


sudo docker run -it --name CONTAINERNAME -v /host:/guest -p hostportno:guestportno 

My container is working fine.
I am trying to migrate my container to a new docker-compose image using docker-compose .
I created the docker-compose.yml and specified the necessary parameters, as shown below:

 image: test1 ports - "1234:123" - "2000:223" volumes: - /home:/test -container_name: dockercomposetest working_dir: /test command: /bin/bash 

I cannot migrate using docker-compose.
I get the question as below:

 Conflict. The name "test" is already in use by container eeedac72bb25. You have to delete (or rename) that container to be able to reuse that name. 

Work now - I need to stop and remove the container and do docker-compose up .
Can I restart / transfer the container using docker-compose with the same name as in a regular docker run process.

+5
source share
2 answers

No, you cannot have two containers with the same name. You must select a different name for the container_name field. The previous container must be deleted before you can reuse the name.

If you want Compose to handle the container as if it created it, you must set the container labels as Compose. The easiest way to find them is to create a container (possibly by removing the container_name field) and then using docker inspect to view the labels.

+1
source

You can check if --force-recreate will help:

  docker-compose up --force-recreate 

On the docker-compose up page:

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag.

  --force-recreate 

Recover containers, even if their configuration and image have not changed

0
source

Source: https://habr.com/ru/post/1239964/


All Articles