DEV Community

Cover image for How to resolve Docker Compose Warning WARN[0000] Found orphan containers
Almatin Siswanto
Almatin Siswanto

Posted on

1

How to resolve Docker Compose Warning WARN[0000] Found orphan containers

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I know this is not much but hopefully, you found this post useful somehow. Happy coding!

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more