. Advertisement .
..3..
. Advertisement .
..4..
Are you struggling to find the answer for the problem “Name Already in Use by Container” in Docker? If you are unsure about the method, the post below is what you’re looking for. Take a moment and let’s read our article and you will solve it as well as the relevant expertise in no time.
What is Docker Container?
It is a live-run version of Docker images. While Docker images are read-only files, containers are live, but temporary, and executable assets. The user can interact with them or the administrator can also adjust the settings and conditions as desired using the docker command.
When does the error occur?
The Docker image contains the executable application source code as well as all the tools, libraries, and dependencies that the application code needs to run as a container. When you run a Docker image, it becomes one instance (or multiple instances) of the container. However, most likely during the run, the “Name Already in Use by Container” error will appear, and it is returned as follows:
docker: Error response from daemon: Conflict. The container name "/ittutoria_nginx" is already in use by container "76da8f6d3accc9b6d41c8a98fd492d4b8622804220ee628a438264b8cf4ae3d4".
You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
What causes error?
Docker images are made up of layers, and each layer corresponds to an instance of the image. Whenever a developer makes changes to an image, a new top layer is created and this top layer replaces the previous top layer as the current version of the image. Then the names of the containers cannot be duplicated. If there is a match, the above error will occur.
How to fix error “ Name Already in Use by Container” in Docker?
If you’re getting this error, don’t worry! Here we will give you some solutions to be able to handle it quickly.
Solution 1: Run the command “docker start”
You need to distinguish between two commands docker start
and docker run
. If you run the docker run
command programmatically create a new container so there will be a situation where the versions overlap. Meanwhile, the command docker start
will restart the existing container. And in this situation, the command “docker start
” can solve the above problem for you.
Solution 2: Delete an existing container
With this solution, first check if the program really exists in the duplicate container with the following command:
$ docker ps -a
If it is, proceed to delete it with the command (qgis-desktop-2-4
is the name of container):
$ docker rm qgis-desktop-2-4
or:
$ docker rm -f qgis-desktop-2-4
At this point, you can manipulate to create a new container to avoid duplicates.
Solution 3: Delete an existing container (continue)
Alternatively you can use the following command to bulk list unused containers:
docker container ls -a --filter status=exited --filter status=created
Then use this command to delete them:
docker container prune
Solution 4: Give a different name to the container
Another simple solution is to name the containers differently to avoid duplication. For example you can set the following:
docker run --name ittutoria_nginx_1 -p 80:80 -d nginxdemos/hello:plain-text
docker run --name ittutoria_nginx_2 -p 81:80 -d nginxdemos/hello:plain-text
Then you can check the running containers with the command:
docker ps
The return you might see looks like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f341bb9fe165 nginxdemos/hello:plain-text "/docker-entrypoint.…" 2 seconds ago Up 2 seconds 0.0.0.0:81->80/tcp ittutoria_nginx_2
33883c2b31a7 nginxdemos/hello:plain-text "/docker-entrypoint.…" 12 seconds ago Up 11 seconds 0.0.0.0:80->80/tcp ittutoria_nginx_1
Conclusion
Through all the quick answers and relevant information above, you can confidently handle the error “Name Already in Use by Container” in Docker. If this kind of question appears. Please make a note or save our information so you can easily find these great methods quickly when needed!
Leave a comment