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

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

详细错误提示:
/usr/bin/docker-current: Error response from daemon: Conflict. The container name “/xxx” is already in use by container e3274a72e8d62a0f3022d3201405ce586147b3031c1232452d001ee41fb9c938. You have to remove (or rename) that container to be able to reuse that name…

下面举例说明。

列出本地镜像:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat 8.5.35 78b258e36eed 2 weeks ago 463 MB
docker.io/tomcat latest 6759d91a032b 3 weeks ago 463 MB

创建新的容器:
docker run --name tomcat8080 -d -p 8080:8080 tomcat
/usr/bin/docker-current: Error response from daemon: Conflict. The container name “/tomcat8080” is already in use by container e3274a72e8d62a0f3022d3201405ce586147b3031c1232452d001ee41fb9c938. You have to remove (or rename) that container to be able to reuse that name…
See ‘/usr/bin/docker-current run --help’.
上面创建新容器出现了错误,提示:容器名被占用,须移除或重命名后才能使用这个容器名。

【解决办法】

  1. 先查看所有的容器
    docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    e3274a72e8d6 tomcat “catalina.sh run” 2 weeks ago Exited (130) 19 minutes ago tomcat8080
    看到了这个名为 “tomcat8080” 的容器,并且这个容器是非运行(Exited)状态。

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

  1. 移除这个“tomcat8080”容器
    docker rm e3274a72e8d6
    e3274a72e8d6
    再看,容器已经移除:
    docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

  2. 然后再创建新容器
    docker run --name tomcat8080 -d -p 8080:8080 tomcat
    af52e9ac72c0393b5468cccf235ad70a7bf6a6b4ed30122b345b3758875d8911
    新容器创建成功,并且是运行状态:
    docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    af52e9ac72c0 tomcat “catalina.sh run” 7 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp tomcat8080

问题解决。

你可能感兴趣的:(docker)