How to fix 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. in Docker
This warning appears when Docker Compose detects containers that belong to the same project but are no longer defined in your docker-compose.yml file. It typically happens after renaming or removing services, or when multiple compose files share the same project name.
Quick fix
Fixes 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.
# Remove orphans when starting services
docker-compose up -d --remove-orphans
# Or remove orphans when stopping services
docker-compose down --remove-orphans- Remove orphan containers with the --remove-orphans flag
- Set a unique project name to avoid conflicts
- Suppress the warning if orphans are intentional
- Manually clean up orphan containers
# Remove orphans when starting servicesdocker-compose up -d --remove-orphans# Or remove orphans when stopping servicesdocker-compose down --remove-orphansWARN[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.
What this error means
When you run Docker Compose commands, it identifies containers using a project name, which by default is the name of the directory containing your `docker-compose.yml` file. This project name gets assigned to containers as the `com.docker.compose.project` label. The "Found orphan containers" warning appears when Docker Compose finds containers with a matching project label that aren't defined in the current `docker-compose.yml` file. This commonly happens in several scenarios: - **Removed services**: You deleted a service from your compose file, but its container still exists - **Renamed services**: You changed a service name, creating a new container while the old one remains - **Same directory name**: Two different projects happen to be in directories with the same name, causing their containers to share a project name - **Multiple compose files**: Running different compose files from the same directory without specifying unique project names This is a warning, not an error - your containers will still start normally. However, orphan containers consume resources and can cause confusion during debugging.
Typical symptoms
- Warning message shows 'Found orphan containers' when running docker-compose commands
- Message suggests using --remove-orphans flag
- Containers from old/renamed services still appear in 'docker ps -a'
- Multiple containers exist for what should be a single service
- Warning appears after editing docker-compose.yml to remove or rename services
Common causes
- Service was removed from docker-compose.yml but its container still exists
- Service was renamed in docker-compose.yml, leaving the old container orphaned
- Multiple docker-compose files in the same directory have different service definitions
- Two different projects share the same directory name (default project name)
- Running docker-compose from a directory with an existing project name used elsewhere
- Switching between different docker-compose.yml files without cleaning up
How to fix "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."
The simplest solution is to let Docker Compose remove the orphan containers automatically:
# Remove orphans when starting services
docker-compose up -d --remove-orphans
# Or remove orphans when stopping services
docker-compose down --remove-orphansThis tells Docker Compose to stop and remove any containers that belong to this project but aren't defined in the current compose file.
If you have multiple projects or compose files that might conflict, give each a unique project name. There are three ways to do this:
Option 1: Use the -p flag
docker-compose -p my-unique-project up -dOption 2: Set COMPOSE_PROJECT_NAME in a .env file
Create a .env file in the same directory as your docker-compose.yml:
COMPOSE_PROJECT_NAME=my-unique-projectOption 3: Add a top-level name in docker-compose.yml
name: my-unique-project
services:
web:
image: nginx
# ... other servicesThis ensures different projects don't interfere with each other even if they're in directories with the same name.
If the orphan containers are expected and you don't want to remove them, you can suppress the warning:
Set environment variable for a single command:
COMPOSE_IGNORE_ORPHANS=true docker-compose up -dOr add to your .env file for permanent effect:
COMPOSE_IGNORE_ORPHANS=trueUse this option when you intentionally have containers from different compose files that you want to keep running.
If you want to inspect and selectively remove orphan containers:
# List all containers including stopped ones
docker ps -a
# Find containers belonging to the current project
docker ps -a --filter "label=com.docker.compose.project=$(basename $PWD)"
# Remove specific containers manually
docker rm -f <container_name_or_id>This gives you more control if you only want to remove certain orphaned containers.
When working with multiple compose files (e.g., docker-compose.yml and docker-compose.test.yml), specify all files you want to use:
# Explicitly use multiple compose files
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -dOr set the COMPOSE_FILE environment variable in your .env file:
COMPOSE_FILE=docker-compose.yml:docker-compose.test.ymlThis tells Docker Compose about all the services across both files, preventing false orphan warnings.
Advanced notes
Understanding project names: Docker Compose uses the project name as a namespace for all resources (containers, networks, volumes). The default project name is the directory name, converted to lowercase with special characters removed. You can verify the current project name with:
docker-compose config | grep -i nameWhy --remove-orphans doesn't work with some commands: Commands like docker-compose run and docker-compose create may suggest using --remove-orphans, but they don't actually accept this flag. In these cases, run docker-compose down --remove-orphans first, then execute your command.
Complete cleanup: For a thorough cleanup including volumes and images:
docker-compose down --volumes --rmi all --remove-orphansCI/CD considerations: In automated pipelines, always use explicit project names and --remove-orphans to ensure clean state:
docker-compose -p ci-build-${BUILD_NUMBER} up -d --remove-orphans
# ... run tests ...
docker-compose -p ci-build-${BUILD_NUMBER} down --volumes --remove-orphansFrequently asked questions
- What does "WARN[0000] Found orphan containers ([container-name]) for this project" mean?
- yml file. project label. yml file.
- How do I fix "WARN[0000] Found orphan containers ([container-name]) for this project"?
- This warning appears when Docker Compose detects containers that belong to the same project but are no longer defined in your docker-compose.yml file. It typically happens after renaming or removing services, or when multiple compose files share the same project name.
- What causes "WARN[0000] Found orphan containers ([container-name]) for this project"?
- Service was removed from docker-compose.yml but its container still exists Service was renamed in docker-compose.yml, leaving the old container orphaned Multiple docker-compose files in the same directory have different service definitions
- Is the "WARN[0000] Found orphan containers ([container-name]) for this project" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐ฌStack Overflow: docker compose orphan containers warning(Stack Overflow)
- ๐
- ๐
- ๐
- ๐
- ๐