docker error - 'name is already in use by container'

后端 未结 18 2022
暖寄归人
暖寄归人 2020-12-12 08:14

Running the docker registry with below command always throws an error:

dev:tmp me$ docker run \\
     -d --name registry-v1 \\
     -e SETTINGS_         


        
相关标签:
18条回答
  • 2020-12-12 08:50

    Just to explain what others are saying (it took me some time to understand) is that, simply put, when you see this error, it means you already have a container and what you have to do is run it. While intuitively docker run is supposed to run it, it doesn't. The command docker run is used to only START a container for the very first time. To run an existing container what you need is docker start $container-name. So much for asking developers to create meaningful/intuitive commands.

    0 讨论(0)
  • 2020-12-12 08:50

    Here is how I solved this on ubuntu 18:

    1. $ sudo docker ps -a
    2. copy the container ID

    For each container do:

    1. $ sudo docker stop container_ID
    2. $ sudo docker rm container_ID
    0 讨论(0)
  • 2020-12-12 08:51

    When you are building a new image you often want to run a new container each time and with the same name. I found the easiest way was to start the container with the --rm option:

    --rm        Automatically remove the container when it exits
    

    e.g.

    docker run --name my-micro-service --rm <image>
    

    Sadly it's used almost randomly in the examples from the docs

    0 讨论(0)
  • 2020-12-12 08:51

    You can remove it with command sudo docker rm YOUR_CONTAINER_ID, then run a new container with sudo docker run ...; or restart an existing container with sudo docker start YOUR_CONTAINER_ID

    0 讨论(0)
  • 2020-12-12 08:52

    That means you have already started a container in the past with the parameter docker run --name registry-v1 ....

    You need to delete that first before you can re-create a container with the same name with docker rm registry-v1. When that container is sill running you need to stop it first before you can delete it with docker stop registry-v1. Or simply choose a different name for the new container.

    To get a list of existing containers and their names simply invoke docker ps -a.

    0 讨论(0)
  • 2020-12-12 08:54

    You have 2 options to fix this...

    1. Remove previous container using that name, with the command docker rm $(docker ps -aq --filter name=myContainerName)

      OR

    2. Rename current container to a different name i.e change this portion --name registry-v1 to something like --name myAnotherContainerName

    You are getting this error because that container name ( i.e registry-v1) was used by another container in the past...even though that container may have exited i.e (currently not in use).

    0 讨论(0)
提交回复
热议问题