DEV Community

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

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!

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay