Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Docker Compose warns about orphan containers for the project

ErrorCompose displays a warning about orphaned containers

Short answer

Compose found containers carrying your project's label whose service is no longer in the Compose file. That follows a removed or renamed service, or a project name shared by two files. Run docker compose up --remove-orphans, or set a distinct project name so unrelated stacks stop mixing.

  • Applies to Docker Compose 2, Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every container of this project, including stopped ones, and compare it with the services in your Compose file. The ones not in the file are the orphans.

    docker compose ps -a
    docker compose config --services
  2. 2Match what you see, then jump to its fix

    1. 1The warning names a container whose service you deleted or renamed recentlyA service was removed or renamed in the Compose fileFix
    2. 2The orphans belong to a different application that lives in a folder with the same nameTwo Compose files share one project nameFix
    3. 3You deliberately run several files for one project, for example with -f, and the orphan warning is just noiseThe warning is wanted off for good, or cleaned up automaticallyFix

What does the error look like?

  • Compose displays a warning about orphaned containers

Cause 1 of 3

A service was removed or renamed in the Compose file

1Check

Containers for the old service name still exist, and Compose sees them as part of the project but not defined by the current file. The environment-variable docs define orphans exactly this way.

docker compose ps -a
docker compose config --services

2Fix

Remove the leftovers when you bring the stack up. Compose describes this option as removing containers for services not defined in the Compose file.

docker compose up -d --remove-orphans

3Verify

The warning is gone and only current services are listed.

docker compose ps -a

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

Two Compose files share one project name

1Check

The project name defaults to the base name of the directory holding the Compose file. Two projects in folders with the same base name, such as app, end up as one project. Compose resolves the name from -p, then COMPOSE_PROJECT_NAME, then the name: attribute, then the folder.

docker compose ls -a

2Fix

Give each project its own name with a top-level name: in its Compose file. Then clean up the old group of containers once.

# compose.yaml
name: shop-backend
services:
  web:
    image: nginx

3Verify

The projects are listed separately.

docker compose ls -a

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The warning is wanted off for good, or cleaned up automatically

1Check

Compose has two switches. COMPOSE_IGNORE_ORPHANS stops it looking for orphans. COMPOSE_REMOVE_ORPHANS removes them when updating a stack, and with it off Compose only shows the warning.

docker compose config --services

2Fix

Pick one: ignore the check for this project, or let Compose delete orphans on every update. Delete only when you are sure nothing else uses the project name.

# .env next to compose.yaml
COMPOSE_IGNORE_ORPHANS=true
# or
COMPOSE_REMOVE_ORPHANS=true

3Verify

Run up again and confirm the warning no longer shows.

docker compose up -d

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Set name: at the top of every Compose file so the folder name does not decide the project.
  • Use docker compose down --remove-orphans before renaming or deleting services.
  • Keep one project per Compose setup; use -f overrides only for the same project.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.