美文网首页后端入门
docker 容器名称冲突问题解决

docker 容器名称冲突问题解决

作者: 某尤 | 来源:发表于2016-03-18 10:12 被阅读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

    相关文章

      网友评论

        本文标题:docker 容器名称冲突问题解决

        本文链接:https://www.haomeiwen.com/subject/cunclttx.html