ChatGPT解决这个技术问题 Extra ChatGPT

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

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?


P
Peter Mortensen

It looks like a container with the name qgis-desktop-2-4 already exists in the system. 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.


hey @Dharmit thanks for the comment. I tried that but now get the following error message groupadd: GID '0' already exists useradd: user 'root' already exists No protocol specified Warning: qgis.bin: cannot connect to X server unix:0.0
It seems like the image tries to make the user root, and a root group which both in fact already exists. Docker uses root:root as default user and group. But the first issue is fixed when you removed the first container.
hmm, weird so why was it working fine to begin with i.e. 3 - 4 months. Any ideas what I can do to fix this?!
How can we just restart existing container instead of killing old one and invoking with same name again?
@DhaneshMane docker restart, or docker stop & docker start should help you.
G
Gryu

Instead of command: docker run

You should use:

docker start **CONTAINER ID**

because the container is already exist

More info


'docker start' doesn't give options to enable host networking, mount volumes from the command line, and other options that are necessary in my case. So personally I had to delete (prune) then run.
@horsehair when I use docker start it reestablishes all exposed ports and volume mounts. So depending on how you initially ran your container those settings should resolve with docker start.
Yeah, this kind of sucks as I want it to work both ways....start/run for developers that join the team and for developers who ran it once before. it's not very idempotent :(. oh well, I guess I have to do some if logic in the bash scripts
N
Noam Manos

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.

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.).


docker ps -a list me also all the containers as @peter mortensen mentioned above.
K
Karl Adler

For people landing here from google like me and just want to build containers using multiple docker-compose files with one shared service:

Sometimes you have different projects that would share e.g. a database docker container. Only the first run should start the DB-Docker, the second should be detect that the DB is already running and skip this. To achieve such a behaviour we need the Dockers to lay in the same network and in the same project. Also the docker container name needs to be the same.

1st: Set the same network and container name in docker-compose

docker-compose in project 1:

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:

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.

docker-compose -p {projectname} up


A
Alex Nolasco

No issues with the latest 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.