229

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?

Gryu
  • 2,102
  • 2
  • 16
  • 29
marty_c
  • 5,779
  • 5
  • 24
  • 27

8 Answers8

351

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dharmit
  • 5,498
  • 2
  • 27
  • 30
  • 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` – marty_c Jul 28 '15 at 13:41
  • 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. – luxas Jul 28 '15 at 13:46
  • 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?! – marty_c Jul 28 '15 at 21:34
  • 1
    How can we just restart existing container instead of killing old one and invoking with same name again? – Dhanesh Mane Oct 17 '16 at 18:03
  • 15
    @DhaneshMane `docker restart`, or `docker stop` & `docker start` should help you. – Dharmit Oct 18 '16 at 05:31
  • "The last column in the above command's output is for names." This is very useful. Had missed chcking and was assuming its Not there – nanosoft Aug 05 '22 at 11:43
103

Instead of command: docker run

You should use:

docker start **CONTAINER ID**

because the container is already exist

More info

Gryu
  • 2,102
  • 2
  • 16
  • 29
nasir taha
  • 1,329
  • 1
  • 10
  • 7
  • 3
    '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. – Ken - Enough about Monica Feb 08 '20 at 17:12
  • 3
    @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. – djchapm May 11 '20 at 16:28
  • 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 – Dean Hiller Jun 26 '20 at 17:53
50

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

Noam Manos
  • 15,216
  • 3
  • 86
  • 85
16

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

Karl Adler
  • 15,780
  • 10
  • 70
  • 88
4

I bumped into this error while executing a docker run on my splunk dev server . These steps came handy:

  1. Execute : docker container ls -a
  2. Get the containerName from “NAMES” column, the output of step 1.
  3. Execute : docker restart <containerName>
Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35
3

The below command will resolve the issue

docker rm -f container_name
Vijay
  • 311
  • 3
  • 10
  • 1
    This is the same solution as in [this other answer](https://stackoverflow.com/a/31676806/2227743). – Eric Aya Aug 09 '22 at 14:41
0

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.

Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81
0

Three easy solutions

(choose one)

  1. Omit --name when starting the container (you don't have to name it, and if you don't, docker will just give it a random name)

  2. Provide a different name (i.e. change --name mycontainer to --name mycontainer2)

  3. Delete the container that already exists with that name. E.g.

docker container rm <container_name>

Notes

  • The error occurs when you try to create a container but a container of the same name already exists

  • You should be able to spot the existing one by running

docker ps -a | grep <container_name>

or just docker ps -a to inspect all existing containers.

stevec
  • 41,291
  • 27
  • 223
  • 311