Reputation: 1367
I am bringing up my project dependencies using docker-compose. So far this used to work
docker-compose up -d --no-recreate;
However today I tried running the project again after couple of weeks and I was greeted with error message
Creating my-postgres ... error
ERROR: for my-postgres Cannot create container for service postgres: b'Conflict. The container name "/my-postgres" is already in use by container "dbd06bb1d99eda6f075ea688df16e8b355e559e1759f084dee8f3cddfc535b0b". You have to remove (or rename) that container to be able to reuse that name.'
ERROR: for postgres Cannot create container for service postgres: b'Conflict. The container name "/my-postgres" is already in use by container "dbd06bb1d99eda6f075ea688df16e8b355e559e1759f084dee8f3cddfc535b0b". You have to remove (or rename) that container to be able to reuse that name.'
ERROR: Encountered errors while bringing up the project.
My docker-compose.yml file is
postgres:
container_name: my-postgres
image: postgres:latest
ports:
- "15432:5432"
Docker version is
Docker version 19.03.1, build 74b1e89
Docker compose version is
docker-compose version 1.24.1, build 4667896b
Intended behavior of this call is to:
Upvotes: 23
Views: 33759
Reputation: 3483
Basically, it boils down to the following: (use them base on your use cases)
To clear containers:
docker rm -f $(docker ps -a -q)
To clear images:
docker rmi -f $(docker images -a -q)
To clear volumes:
docker volume rm $(docker volume ls -q)
To clear networks:
docker network rm $(docker network ls | tail -n+2 | awk '{if($2 !~ /bridge|none|host/){ print $1 }}')
Upvotes: 6
Reputation: 3463
Well...the error message seems pretty straightforward to me...
The container name "/my-postgres" is already in use by container
If you just want to restart where you left, you should use docker-compose start
.
Otherwise, just clean up your workspace before running it :
docker-compose down
docker-compose up -d
Upvotes: 3
Reputation: 557
It's caused by being in a different directory than when you last ran docker-compose up
. One option is to change back to the original directory. Or if you've configured it as a systemd
service you can use systemctl
.
Upvotes: 5
Reputation: 382
In my case I moved the project in an other directory.
When I tryed to run docker-compose up
it failed because of some conflicts.
With command docker system prune
I resolved them.
Upvotes: 20
Reputation: 21
Remove --no-recreate flag from your docker-compose command. And execute the command again.
$docker-compose up -d
If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation, docker-compose up picks up the changes by stopping and recreating the containers. To prevent Compose from picking up changes, use the --no-recreate flag.
official docker docs.Link
Upvotes: 2
Reputation: 159722
Docker Compose normally assigns a container name based on its current project name and the name of the services:
block. Specifying container_name:
explicitly overrides this; but, it means you can’t launch multiple copies of the same Compose file with different project names (from different directories) because the container name you’ve explicitly chosen won’t be used.
You almost never care what the container name is explicitly. It only really matters if you’re trying to use plain docker
commands to manipulate Compose-managed containers; it has no impact on inter-service communication. Just delete the container_name:
line.
(For similar reasons you can almost always delete hostname:
and links:
sections if you have them with no practical impact on your overall system.)
Upvotes: 33