Solution to the problem of “the container name” / xxx “is already in use by container xxxxxxxxx…” when creating a new docker container

Time:2021-1-11

Solution to the problem of “the container name” / xxx “is already in use by container xxxxxxxxx…” when creating a new docker container

1. Detailed error prompt:

/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/rabbitmq" is already in use by container 8278c2b3d8ded022cf2baa3e0c41c339733331cd6e5b21720bc5db10d8afe7a. You have to remove (or rename) that container to be able to reuse that name..

2. The following example lists the local images:

3. Create a new container:(rabbitmq)

docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq 5335b737c380

(there is an error in creating a new container above. Prompt: the container name is occupied. You must remove or rename it before you can use it.)

4. Check all containers first:

docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED           STATUS                       PORTS   NAMES
e9ab55123cc8        kiban6.4.3                  "/usr/local/bin/ki..."   5 weeks ago       Exited (137) 11 minutes ago          kibana
a45eb1980ab8        rabbitmq                    "/usr/local/bin/do..."   5 weeks ago       Exited (143) 11 minutes ago          rabbitmq
c15d671e01b8        mobz/elasticsearch-head:5   "/bin/sh -c 'grunt..."   5 weeks ago       Exited (137) 5 weeks ago             zen_kalam

You see the container called “rabbitmq” and the container is not in the exited state.

Note: “docker PS” is to view the currently running container, “docker PS – a” is to view all containers (including stopped containers).

5. Remove the “rabbitmq” container:

docker rm 5335b737c380

6. Look again, the container has been removed:

docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED           STATUS                       PORTS   NAMES
e9ab55123cc8        kiban6.4.3                  "/usr/local/bin/ki..."   5 weeks ago       Exited (137) 11 minutes ago          kibana
c15d671e01b8        mobz/elasticsearch-head:5   "/bin/sh -c 'grunt..."   5 weeks ago       Exited (137) 5 weeks ago             zen_kalam

7. Then create a new container:

docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq 5335b737c380

 (image_ (remember to replace)

8. The new container is created successfully and is running

docker ps -a

 

9. OK, problem solved!