创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx…”问题的解决办法

  • A+
所属分类:linux技术
摘要

1.详细错误提示: 2.下面举例说明,列出本地镜像: 3.创建新的容器:( rabbitmq)


创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

1.详细错误提示:

创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

/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.下面举例说明,列出本地镜像:

创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

3.创建新的容器:(rabbitmq)

[root@localhost ~]# docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq 5335b737c380

创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

(上面创建新容器出现了错误,提示:容器名被占用,须移除或重命名后才能使用这个容器名。)

4.先查看所有的容器:

[root@localhost ~]# 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

看到了这个名为 “rabbitmq” 的容器,并且这个容器是非运行(Exited)状态。

:“docker ps” 是查看当前运行的容器,“docker ps -a” 是查看所有容器(包括停止的)。

5.移除这个“rabbitmq”容器:

[root@localhost ~]# docker rm 5335b737c380

6.再看,容器已经移除:

[root@localhost ~]# 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.然后再创建新容器:

[root@localhost ~]# docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq 自己的image_id

[root@localhost ~]# docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq 5335b737c380 e3f8ec86036f821d783721f4b42d634899e7551b6b752142260a2b6d4e6a5a3c

创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

 (image_id 记得替换)

8.新容器创建成功,并且是运行状态:

[root@localhost ~]# docker ps -a

创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法

 

9.Ok,问题解决!