docker 容器名称冲突问题解决
2016-03-18 本文已影响4605人
某尤
执行 docker run 命令遇到了以下错误
sudo docker run -d -p 3000:3000 --name node-app gemini/demo
FATA[0000] Error response from daemon: Conflict. The name "node-app" is already in use by container 55a8d2226ce2. You have to delete (or rename) that container to be able to reuse that name.
使用 docker ps 命令发现存在运行中的容器名字也叫 "node-app"。
docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd3c0c622af6 gemini/demo:latest "npm start" 18 minutes ago Up 18 minutes 0.0.0.0:3000->3000/tcp node-app
使用命令停止并删除这个容器就可以
docker kill fd3c0c622af6
docker rm fd3c0c622af6
知道原因后可以将以上操作简化为以下命令
docker kill $(docker ps -q); docker rm $(docker ps -a -q)
docker ps 命令详情:
docker ps --help
Usage: docker ps [OPTIONS]
List containers
-a, --all=false Show all containers (default shows just running)
--before= Show only container created before Id or Name
-f, --filter=[] Filter output based on conditions provided
--help=false Print usage
-l, --latest=false Show the latest created container, include non-running
-n=-1 Show n last created containers, include non-running
--no-trunc=false Don't truncate output
-q, --quiet=false Only display numeric IDs
-s, --size=false Display total file sizes
--since= Show created since Id or Name, include non-running