简体   繁体   English

Docker 来自守护进程的错误响应:“冲突......容器已在使用”

[英]Docker error response from daemon: "Conflict ... already in use by container"

I've been using Docker on my PC to run Quantum GIS with the following instructions I've found here: docker-qgis-desktop - A simple docker container that runs QGIS desktop我一直在我的 PC 上使用 Docker 运行 Quantum GIS,并按照我在此处找到的以下说明: docker-qgis-desktop - 运行 QGIS 桌面的简单 docker 容器

Everything has been running fine until last week when I started to get this error message:直到上周我开始收到此错误消息时,一切都运行良好:

 Error response from daemon: Conflict. The name "qgis-desktop-2-4" is already in use by container 235566ae17b8. You have to delete (or rename) that container to be able to reuse that name.

I'm not entirely sure what this means despite searching for clues on this site.尽管在此站点上搜索了线索,但我并不完全确定这意味着什么。 I hadn't changed anything prior to this happening and have been successfully launching the container with this command:在发生这种情况之前,我没有进行任何更改,并且已经使用以下命令成功启动了容器:

sudo docker run --rm --name="qgis-desktop-2-4"     -i -t     -v ${HOME}:/home/${USER}     -v /tmp/.X11-unix:/tmp/.X11-unix     -e DISPLAY=unix$DISPLAY     kartoza/qgis-desktop:latest

How can I fix this?我怎样才能解决这个问题?

It looks like a container with the name qgis-desktop-2-4 already exists in the system.看起来系统中已经存在一个名为qgis-desktop-2-4的容器。 You can check the output of the below command to confirm if it indeed exists:您可以检查以下命令的输出以确认它是否确实存在:

$ docker ps -a

The last column in the above command's output is for names.上述命令输出中的最后一列用于名称。

If the container exists, remove it using:如果容器存在,请使用以下命令将其删除:

$ docker rm qgis-desktop-2-4

Or forcefully using,或者强行使用,

$ docker rm -f qgis-desktop-2-4

And then try creating a new container.然后尝试创建一个新容器。

Instead of command: docker run代替命令: docker run

You should use:你应该使用:

docker start **CONTAINER ID**

because the container is already exist因为容器已经存在

More info 更多信息

I got this error quite a lot, so now I do a batch removal of all unused containers at once:我经常遇到这个错误,所以现在我一次批量删除所有未使用的容器:

docker container prune 

add -f to force removal without prompt.添加-f以在没有提示的情况下强制删除。

To list all unused containers (without removal):列出所有未使用的容器(不移除):

docker container ls -a --filter status=exited --filter status=created 

See here more examples how to prune other objects (networks, volumes, etc.).请参阅此处的更多示例,了解如何修剪其他对象(网络、卷等)。

For people landing here from google like me and just want to build containers using multiple docker-compose files with one shared service:对于像我这样从谷歌登陆这里并且只想使用多个 docker-compose 文件和一个共享服务构建容器的人:

Sometimes you have different projects that would share eg a database docker container.有时您有不同的项目会共享例如一个数据库 docker 容器。 Only the first run should start the DB-Docker, the second should be detect that the DB is already running and skip this.只有第一次运行应该启动 DB-Docker,第二次应该检测到 DB 已经在运行并跳过这个。 To achieve such a behaviour we need the Dockers to lay in the same network and in the same project .为了实现这样的行为,我们需要 Docker 位于同一个网络和同一个项目中 Also the docker container name needs to be the same. docker 容器名称也需要相同。

1st: Set the same network and container name in docker-compose第一:在docker-compose中设置相同的网络和容器名称

docker-compose in project 1:项目 1 中的 docker-compose:

version: '3'

services:
    service1:
        depends_on:
            - postgres
        # ...
        networks:
            - dockernet

    postgres:
        container_name: project_postgres
        image: postgres:10-alpine
        restart: always
        # ...
        networks:
            - dockernet

networks:
    dockernet:

docker-compose in project 2:项目 2 中的 docker-compose:

version: '3'

services:
    service2:
        depends_on:
            - postgres
        # ...
        networks:
            - dockernet

    postgres:
        container_name: project_postgres
        image: postgres:10-alpine
        restart: always
        # ...
        networks:
            - dockernet

networks:
    dockernet:

2nd: Set the same project using -p param or put both files in the same directory.第二:使用-p param设置相同的项目或将两个文件放在同一目录中。

docker-compose -p {projectname} up

No issues with the latest kartoza/qgis-desktop最新的 kartoza/qgis-desktop 没有问题

I ran我跑了

docker pull kartoza/qgis-desktop

followed by其次是

docker run -it --rm --name "qgis-desktop-2-4" -v ${HOME}:/home/${USER} -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY kartoza/qgis-desktop:latest

I did try multiple times without the conflict error - you do have to exit the app beforehand.我确实尝试了多次而没有出现冲突错误 - 您必须事先退出应用程序。 Also, please note the parameters do differ slightly.另外,请注意参数确实略有不同。

The below command will resolve the issue下面的命令将解决问题

docker rm -f container_name

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 docker:来自守护进程的错误响应:无效模式:/usr/src/app - docker: Error response from daemon: invalid mode: /usr/src/app Docker 来自守护程序的错误响应:无法安装本地卷 - Docker Error response from daemon: failed to mount local volume 为什么我的 NVIDIA docker 不工作? 来自守护进程的错误响应? - why is my NVIDIA docker not working? Error response from daemon? docker:来自守护程序的错误响应:找不到网络 mysql_net - docker: Error response from daemon: network mysql_net not found 如何解决“docker:来自守护进程的错误响应:OCI 运行时创建失败:无法检索 OCI 运行时错误” - How to solve "docker: Error response from daemon: OCI runtime create failed: unable to retrieve OCI runtime error" “来自守护进程的错误响应:无法启动容器......没有这样的文件或目录”在Oracle Linux上运行hello-world - “Error response from daemon: Cannot start container … no such file or directory” on Oracle Linux running hello-world 当我尝试使用docker pull peterevans / nominatim时来自守护进程的错误响应 - Error response from daemon when i'm trying docker pull peterevans/nominatim 找不到flocker插件,来自守护程序的错误响应 - flocker plugin not found, error response from daemon 来自守护进程的错误响应:获取 https://registry-1.docker.io/v2/:远程错误:tls:握手失败 - Error response from daemon: Get https://registry-1.docker.io/v2/: remote error: tls: handshake failure 在Docker守护程序中初始化网络控制器时出错 - Error initializing network controller in docker daemon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM