Running the docker
registry with below command always throws an error:
dev:tmp me$ docker run \\
-d --name registry-v1 \\
-e SETTINGS_
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.
Here is how I solved this on ubuntu 18:
$ sudo docker ps -a
For each container do:
$ sudo docker stop container_ID
$ sudo docker rm container_ID
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
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
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
.
You have 2 options to fix this...
Remove previous container using that name, with the command docker rm $(docker ps -aq --filter name=myContainerName)
OR
--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).