docker run -> name is already in use by container

2019-01-29 19:46发布

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

dev:tmp me$ docker run \
     -d --name registry-v1 \
     -e SETTINGS_FLAVOR=local \
     -e STORAGE_PATH=/registry \
     -e SEARCH_BACKEND=sqlalchemy \
     -e LOGLEVEL=DEBUG \
     -p 5000:5000 \
     registry:0.9.1
Error response from daemon: Conflict. The name "registry-v1" is already in use by container f9e5798a82e0. You have to delete (or rename) that container to be able to reuse that name.

How to prevent this error ?

标签: docker
9条回答
唯我独甜
2楼-- · 2019-01-29 20:00

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

查看更多
一夜七次
3楼-- · 2019-01-29 20:01

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.

查看更多
做个烂人
4楼-- · 2019-01-29 20:01

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

查看更多
成全新的幸福
5楼-- · 2019-01-29 20:16

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

查看更多
beautiful°
6楼-- · 2019-01-29 20:17

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
查看更多
对你真心纯属浪费
7楼-- · 2019-01-29 20:20

Here what i did, it works fine.

step 1:(it lists docker container with its name)

docker ps -a

step 2:

docker rm name_of_the_docker_container
查看更多
登录 后发表回答