The container name "/postgres" is already in use by container "*"
See original GitHub issueWhat happened?
When I tried to create and run a new project with docker-compose I got these errors:
ERROR: for postgres Cannot create container for service postgres: Conflict. The container name "/postgres" is already in use by container "...". You have to remove (or rename) that container to be able to reuse that name.
ERROR: for docs Cannot create container for service docs: Conflict. The container name "/docs" is already in use by container "...". You have to remove (or rename) that container to be able to reuse that name.
ERROR: for postgres Cannot create container for service postgres: Conflict. The container name "/postgres" is already in use by container "...". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
What should’ve happened instead?
Should run the new project without any problem. When I renamed the containers they worked. We could add the project slug name to container_name
.
Additional details
I created a new project with docker support, then:
docker-compose -f local.yml build
Finally:
docker-compose -f local.yml up
$ docker-compose -f local.yml upCreating network “test_api_default” with the default driver Creating volume “test_api_local_postgres_data” with default driver Creating volume “test_api_local_postgres_data_backups” with default driver Creating postgres … Creating docs … error
Creating postgres … error ontainer to be able to reuse that name.
ERROR: for postgres Cannot create container for service postgres: Conflict. The container name “/postgres” is already in use by container “*”. You have to remove (or rename) that container to be able to reuse that name.
ERROR: for docs Cannot create container for service docs: Conflict. The container name “/docs” is already in use by container “*”. You have to remove (or rename) that container to be able to reuse that name.
ERROR: for postgres Cannot create container for service postgres: Conflict. The container name “/postgres” is already in use by container “*”. You have to remove (or rename) that container to be able to reuse that name. ERROR: Encountered errors while bringing up the project.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
When you remove the container name definition for the docker-compose services, the current folders name is used as prefix for the container name. By default this is the project slug. Removing the container names would also allow to pass the
--project-name
option to docker-compose to setup several environments (due to port collisions only one can run at a time though).My preferred way would be to remove the container_name definitions from the docker-compose files and add the
--project-name={{project_slug}}
option in the documentation.I noticed that it seems that container names are set properly in the
production.yml
file. I solved this error by adding<project_name>_local_
in front of allcontainer_name
fields inlocal.yml
. Like is done inproduction.yml
.This would seem to be a reasonable ‘fix’ in my opinion.