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

后端 未结 18 2023
暖寄归人
暖寄归人 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:54

    Cause

    A container with the same name is still existing.

    Solution

    To reuse the same container name, delete the existing container by:

    docker rm <container name>
    

    Explanation

    Containers can exist in following states, during which the container name can't be used for another container:

    • created
    • restarting
    • running
    • paused
    • exited
    • dead

    You can see containers in running state by using :

    docker ps
    

    To show containers in all states and find out if a container name is taken, use:

    docker ps -a
    
    0 讨论(0)
  • 2020-12-12 08:56

    I was running into this issue that when I run docker rm (which usually works) I would get:

    Error: No such image

    The easiest solution to this is removing all stopped containers by running:

    docker container prune
    
    0 讨论(0)
  • 2020-12-12 08:57

    removing all the exited containers

    docker rm $(docker ps -a -f status=exited -q)
    
    0 讨论(0)
  • 2020-12-12 08:58

    I got confused by this also. There are two commands relevant here:

    docker run Run a command in a new container

    docker start Start one or more stopped containers

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

    I have solved the issue by doing following steps and I hope it helps.

    1. Type docker ps -a to list all the containers in your system.
    2. Check the NAMES part where you have initialized your docker container.
    3. Then type docker rm --force name_of_container
    4. Install the docker container as you wish.

    I had problem using NIFI and I have removed and reinstalled using docker. Good luck.

    0 讨论(0)
  • 2020-12-12 09:01

    I'm just learning docker and this got me as well. I stopped the container with that name already and therefore I thought I could run a new container with that name.

    Not the case. Just because the container is stopped, doesn't mean it can't be started again, and it keeps all the same parameters that it was created with (including the name).

    when I ran docker ps -a that's when I saw all the dummy test containers I created while I was playing around.

    No problem, since I don't want those any more I just did docker rm containername at which point my new container was allowed to run with the old name.

    Ah, and now that I finish writing this answer, I see Slawosz's comment on Walt Howard's answer above suggesting the use of docker ps -a

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