Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-Compose Issue with container name

I have created a docker image with required packages. I have run 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 up and running fine.
I am trying to migrate my container to a new docker image using docker-compose.
I have created docker-compose.yml file and specified the required parameters as shown below:

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

I am unable to migrate it using docker-compose.
I am getting issue as stated 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 around currently is I have to stop and remove the container and perform docker-compose up.
Can I not restart/migrate a container using docker-compose with same name as I have started in normal docker run process.

like image 501
Jeevitha G Avatar asked Jan 06 '16 06:01

Jeevitha G


1 Answers

No, you can't have two containers with the same name. You'll have to pick a different name for the container_name field. The previous container needs to be removed before you can re-use the name.

If you wanted Compose to treat the container as if it had created it, you have to set the container labels as Compose does. The easiest way to find these would be to have compose create a container (probably by removing the container_name field), then using docker inspect to view the labels.

like image 179
dnephin Avatar answered Oct 30 '22 06:10

dnephin