Recently I got the docker compose error:
Warning WARN[0000] Found orphan containers ([container-name]) for this project. If you removed or renamed this service in your compose file, you can run this command with the โ remove-orphans flag to clean it up.
when I was trying to deploy more than 1 Postgresql container within my local machine for testing purposes. It was not the Postgresql that had the issue, but rather my docker-compose.yaml file that has the issue. It seems that the issue was because I used the same directory name for both of the Postgresql projects.
Before
services:
my-postgre:
container_name: my_postgre
image: postgres:alpine
restart: always
environment:
POSTGRES_DB: mydb
POSTGRES_USER: me
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
- ./backup:/home/backup
secrets:
- postgres_password
ports:
- 5424:5432
networks:
- my_network
volumes:
pgdata:
networks:
my_network:
driver: bridge
secrets:
postgres_password:
file: ./postgres_password.txt
Based on the documentation here. We can solve the above issue using several ways.
1 Running docker compose
command with -p
parameter.
sudo docker compose -p my-project-name up -d
2 Adding the project name in the docker-compose.yaml
file.
I added the project name to distinguish between the two projects and now both of them running as expected.
After
# adding the project name here
name: my-project-name
services:
my-postgre:
container_name: my_postgre
image: postgres:alpine
restart: always
environment:
POSTGRES_DB: mydb
POSTGRES_USER: me
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
- ./backup:/home/backup
secrets:
- postgres_password
ports:
- 5424:5432
networks:
- my_network
volumes:
pgdata:
networks:
my_network:
driver: bridge
secrets:
postgres_password:
file: ./postgres_password.txt
I know this is not much but hopefully, you found this post useful somehow. Happy coding!
Top comments (0)