question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
MartinSchmidt123commented, Oct 21, 2020

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.

2reactions
abaartcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the “Name Already in Use by Container” Error in ...
When running a docker container with a name we've used before, we'll encounter an error. We look at a few ways to resolve...
Read more >
Docker error response from daemon: "Conflict ... already in ...
It looks like a container with the name qgis-desktop-2-4 already exists in the system. You can check the output of the below command...
Read more >
The container name "/postgres" is already in use by ... - GitHub
The container name "/postgres" is already in use by container "*". You have to remove (or rename) that container to be able to...
Read more >
The container name... is already in use by container... You ...
After my post yesterday unfortunately I am still really struggling to get off the ground with Docker at all. docker: Error response from...
Read more >
Error response from daemon: Conflict. The container name is ...
The container name is already in use by container. In this article, we will see the solution for below error. docker: Error response...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found