Error response from daemon: Error when allocating new name: Conflict. The container name "/webserver" is already in use by container 6c34a8wetwyetwy7463462d329c9601812tywetdyud76767d65f7dc7ea58d8541. You have to remove (or rename) that container to be able to reuse that name.If you see the above error it is because a container with same name exist.
Let’s check our running containers
docker container lsIf you don’t see any running container with that name, check the stopped containers.
docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb45bd14c8987 1fbd5d581e4c "/bin/bash" 2 minutes ago Up 2 minutes competent_keller59b9f5a63ba0 ansible-base "/bin/base" 3 minutes ago Created wizardly_payne6c34a8a6edb6 d355ed3537e9 "/bin/bash" 9 minutes ago Exited (0) 4 minutes ago webserverAbove we can see that we already have a container with name webserver.
So we will rename the old container.
docker rename webserver webserver_oldNow if we check again. Our container is renamed to webserver_old .
docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb45bd14c8987 1fbd5d581e4c "/bin/bash" 4 minutes ago Up 4 minutes competent_keller59b9f5a63ba0 ansible-base "/bin/base" 5 minutes ago Created wizardly_payne6c34a8a6edb6 d355ed3537e9 "/bin/bash" 10 minutes ago Exited (0) 5 minutes ago webserver_oldAnd if you don’t need the old container you can also delete it to free up the space.
docker rm webserver_oldNow if you try to create a container with “webserver” name you should not get any error.