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

LinuxUbuntuDocker

Linux Problem Overview


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?

Linux Solutions


Solution 1 - Linux

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.

Solution 2 - Linux

Instead of command: docker run

You should use:

docker start **CONTAINER ID**

because the container is already exist

More info

Solution 3 - Linux

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

Solution 4 - Linux

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

Solution 5 - Linux

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmarty_cView Question on Stackoverflow
Solution 1 - LinuxDharmitView Answer on Stackoverflow
Solution 2 - Linuxnasir tahaView Answer on Stackoverflow
Solution 3 - LinuxNoam ManosView Answer on Stackoverflow
Solution 4 - LinuxKarl AdlerView Answer on Stackoverflow
Solution 5 - LinuxAlex NolascoView Answer on Stackoverflow