docker compose orphan containers warning

Compose uses the project name (which defaults to the basename of the project directory, but can be specified explicitly) internally to isolate projects from each other. The project name is used to create unique identifiers for all of the project's containers and other resources. For example, if your project name is myapp and it includes two services db and web, then Compose starts containers named myapp_db_1 and myapp_web_1 respectively.

You get the "Found orphan containers" warning because docker-compose detects some containers which belong to another project with the same name.

To prevent different projects from interfering with each other (and suppress the warning) you can set a custom project name by using the -p command line option or the COMPOSE_PROJECT_NAME environment variable. The environment variable can also be set via an environment file (.env in the current working directory by default).


To build on other answers, I create a .env file with my docker compose projects. I have a number of projects that all use the docker directory but are different projects.

To use docker-compose -p is a bit error prone, so creating .env file in the same directory as the docker-compose.yml:

-rw-rw-r--  1 auser auser 1692 Aug 22 20:34 docker-compose.yml
-rw-rw-r--  1 auser auser   31 Aug 22 20:44 .env

alleviates the necessary overhead of remembering -p.

In the .env file, I can now set the COMPOSE_PROJECT_NAME variable:

COMPOSE_PROJECT_NAME=myproject

On running:

docker-compose up -d

the COMPOSE_PROJECT_NAME is substituted without the use of -p.

Reference: https://docs.docker.com/compose/env-file/


docker-compose takes the name of the directory it is in as the default project name.

You can set a different project name by using -p or --project-name. https://docs.docker.com/compose/reference/#use--p-to-specify-a-project-name

I had a similar problem because my projects all had the docker/docker-compose.yml structure.