Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The container name "/postgres" is already in use by container "*" #2849

Closed
dobleuber opened this issue Sep 22, 2020 · 8 comments · Fixed by #3528
Closed

The container name "/postgres" is already in use by container "*" #2849

dobleuber opened this issue Sep 22, 2020 · 8 comments · Fixed by #3528
Labels

Comments

@dobleuber
Copy link

What 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
Logs:
$ docker-compose -f local.yml up

Creating 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.

@dobleuber dobleuber added the bug label Sep 22, 2020
@MartinSchmidt123
Copy link

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.

@sharmi
Copy link

sharmi commented Jan 21, 2021

Hi I develop multiple django projects on my dev machine.

Adding specific names to the containers creates conflict between multiple django projects. The older method of not specifying any container_name worked quite well.

Is there any specific reason we adopted the 'container_name' param?

Is it possible to go back to not specifying container names atleast in local.yml?

@browniebroke
Copy link
Member

This was added in #2545 and the PR explains the rationale. However, the problems described in this issue are more important than the problem it's solving, in my opinion. As I said in the original PR, docker-compose has commands to achieve the same thing.

All things considered, I agree with the suggestion to remove container_name in our compose file.

@abaart
Copy link

abaart commented Mar 24, 2021

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 all container_name fields in local.yml. Like is done in production.yml.

This would seem to be a reasonable 'fix' in my opinion.

@abaart
Copy link

abaart commented Mar 24, 2021

On further inspection, this already seems implemented in local.yml in master (already a long time ago according to blame).
So why this was not rendered properly in my case is a mystery to me...

@fhightower
Copy link
Contributor

fhightower commented May 11, 2021

On further inspection, this already seems implemented in local.yml in master (already a long time ago according to blame).

Thanks for looking into this @abaart, but this is not implemented (as can be seen here). I think you are looking at the image field rather than the container_name field.

@abaart
Copy link

abaart commented May 11, 2021

On further inspection, this already seems implemented in local.yml in master (already a long time ago according to blame).

Thanks for looking into this @abaart, but this is not implemented (as can be seen here). I think you are looking at the image field rather than the container_name field.

You are correct, it seems I mixed up those fields. It is indeed not implemented.

@j0lle
Copy link

j0lle commented Jun 29, 2021

thought is was an easy fix but it breaks postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants