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:
You can still find Docker Compose V1 in the `master` branch. Compose V1 is marked as deprecated, and we'll begin patching only high-severity vulnerabilities or fixing critical bugs until the next milestone. Developers can continue to alias docker-compose to use docker compose.
Stops containers and removes containers, networks, volumes, and images created by up . By default, the only things removed are: Containers for services defined in the Compose file.
no: Containers won't restart automatically. on-failure[:max-retries]: Restart the container if it exits with a non-zero exit code, and provide a maximum number of attempts for the Docker daemon to restart the container.
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.
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.)
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With