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!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay