UPDATE: You can now use the top-level name property in your docker-compose YAML file. This is available from Docker Compose v2.3.3

This is the result of the #745 proposal. An issue which persevered for about 8 years.

Previously: Right now, we can use the .env file to set the custom project name like this:

COMPOSE_PROJECT_NAME=SOMEPROJECTNAME

It's not flexible, but it's better than nothing. Currently, there is an open issue regarding this as a proposal.

Answer from Ayushya on Stack Overflow
🌐
GitHub
github.com › docker › compose › issues › 1123
Project name in docker-compose.yml · Issue #1123 · docker/compose
March 17, 2015 - I know that I can change the project name using the -p option or the COMPOSE_PROJECT_NAME environment variable but IMHO would be useful to have in the docker-compose.yml something like project_name: project1.
Author   fntlnz
Discussions

How to use `COMPOSE_PROJECT_NAME`?
I tried to set it in the docker-compose.yml file with no luck as there's no clear reference on where to place it exactly? I tried to add it in an .env file but didn't read it! I also tried to add it in the command and it keeps giving an error. ... I'm more interested in adding it to the docker-compose file. The main reason is I want to override the default project ... More on github.com
🌐 github.com
18
May 8, 2016
Have access to the derived compose project name inside the docker-compose.yml file.
Description Hello, I have a compose file that creates several services with several volumes. I want to use the project name in the volume path. I know that I can set COMPOSE_PROJECT_NAME before cal... More on github.com
🌐 github.com
19
October 13, 2021
What is the purpose of -p, --project-name option in docker-compose command - Stack Overflow
The project name can be overridden either by passing a -p / --project-name option for each command or setting the COMPOSE_PROJECT_NAME environment variable. Use case is basically to maintain different projects with this. For e.g.:- You can use same docker-compose.yml to have 2 different projects. More on stackoverflow.com
🌐 stackoverflow.com
Docker Compose Logs Missing Project Name
container_name: "${PROJECT}.selenium" ... PROJECT="roots-back" docker compose up -d More on reddit.com
🌐 r/docker
2
1
July 1, 2024
🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › set-docker-compose-project-name
Set Docker Compose project name
November 3, 2021 - Visual Studio Code will respect the value you configure for the Docker Compose project name. The top-level property name in the docker-compose.yml can be used to set the project name.
🌐
Docker
docs.docker.com › manuals › docker compose › specify a project name
Specify a project name | Docker Docs
The default project directory is the base directory of the Compose file. A custom value can also be set for it using the --project-directory command line option. Compose uses a project name to isolate environments from each other.
🌐
DevOps.dev
blog.devops.dev › how-to-customize-your-docker-compose-project-name-a-guide-for-developers-f86c65bbac4e
How to Customize Your Docker Compose Project Name: A Guide for Developers | by Jason Anderson | DevOps.dev
February 23, 2024 - By default, Docker Compose assigns a project name based on the directory name where your docker-compose.yml file resides. While this default behavior is convenient for quick setups, there are scenarios where a custom project name ...
Find elsewhere
🌐
Docker
docs.docker.com › reference › docker compose
docker compose | Docker Docs
The basename of the current directory if no config file is specified Project names must contain only lowercase letters, decimal digits, dashes, and underscores, and must begin with a lowercase letter or decimal digit.
🌐
GitHub
github.com › docker › compose › issues › 3431
How to use `COMPOSE_PROJECT_NAME`? · Issue #3431 · docker/compose
May 8, 2016 - I'm using the latest version of everything and the v2 of docker compose. I tried to set it in the docker-compose.yml file with no luck as there's no clear reference on where to place it exactly? I tried to add it in an .env file but didn...
Author   Mahmoudz
🌐
Docker Docs
docs.docker.com › manuals › docker compose › how compose works
How Compose works | Docker Docs
If you are creating resources on a platform, you must prefix resource names by project and set the label com.docker.compose.project.
🌐
YouTube
youtube.com › watch
Specify a Docker Compose Project Name - YouTube
Docker Compose allows you to manage multi-container Docker applications efficiently. One of its key features is the ability to specify a project name, which ...
Published   December 18, 2024
🌐
Medium
ismailyenigul.medium.com › docker-compose-project-naming-and-network-2be95d319d39
docker-compose project naming and network | by ismail yenigül | Medium
February 11, 2018 - ... the docker-compose will create ... 😆) ... You can change the project name by using — project-name parameter or settings COMPOSE_PROJECT_NAME environment variable....
🌐
GitHub
github.com › docker › compose › issues › 8787
Have access to the derived compose project name inside the docker-compose.yml file. · Issue #8787 · docker/compose
October 13, 2021 - This is not possible because as a docker-compose config command will confirm, the COMPOSE_PROJECT_NAME environment variable is only defined in each service and is not accessible in the docker-compose.yml.
Author   marioja
Top answer
1 of 2
15

If you run docker-compose multiple times, it uses the project name to keep one directory's containers, networks, and volumes separate from another's. Compose doesn't keep any filesystem state or run a background daemon, so metadata on the containers is the only way to keep track of this.

Say you have three Compose projects, and project-a/docker-compose.yml, project-b/docker-compose.yml, and project-c/docker-compose.yml all have a service named db:. Because their project names are different, Compose knows that it shouldn't reuse one db container for another project, it knows which container should be destroyed by docker-compose down, and so on.

A docker-compose -p option is required if you want to run multiple copies of the same Compose stack in the same directory. Otherwise the directory name is used as the default project name, and they'd conflict with each other. That's probably what Visual Studio is thinking about.

If you look at docker ps, docker network ls, and docker volume ls output you will see the name included in object names, project-a_db_1. If you use the detailed inspect forms of these commands you will see some Compose-related labels, and these are what Compose actually looks for.

2 of 2
4

By default, Compose bases the project name on basename of the directory compose commands are run from. The project name can be overridden either by passing a -p / --project-name option for each command or setting the COMPOSE_PROJECT_NAME environment variable.

Use case is basically to maintain different projects with this. For e.g.:- You can use same docker-compose.yml to have 2 different projects.

In the command which you mentioned

docker-compose  -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.override.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose5511081461456614166 --no-ansi config
docker-compose  -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.override.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose5511081461456614166 --no-ansi build
docker-compose  -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\docker-compose.override.yml" -f "D:\Trials\Docker\VsDokWeb\DokWeb3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose5511081461456614166 --no-ansi up -d --no-build --force-recreate --remove-orphans

If you see, it's manipulating the same project and that's why -p is given.

🌐
JetBrains
youtrack.jetbrains.com › issue › PY-34007 › support-Docker-Compose-project-name-argument
support Docker Compose --project-name argument
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Kevin Kouomeu
1kevinson.com › how-to-change-the-project-name-in-docker-compose
How to Change the Project Name in Docker Compose
February 15, 2026 - In Docker Compose, the COMPOSE_PROJECT_NAME environment variable allows you to specify the name of your project. This name is used to prefix the names of containers started with the docker-compose up command.
🌐
Reddit
reddit.com › r/docker › docker compose logs missing project name
r/docker on Reddit: Docker Compose Logs Missing Project Name
July 1, 2024 -

Sorry if this has been answered elsewhere, I am sure it is a stupid question, but I can't seem to find an answer.

I am building containers via Docker Compose using Laravel Sail. Typically, the output for `docker compose logs` would always contain the project + container name. For example, you will see the container's full name with the project here:

```

✔ Network roots-back_sail Created 0.0s

✔ Container roots-back-mailpit-1 Created 0.0s

✔ Container roots-back-selenium-1 Created 0.0s

✔ Container roots-back-redis-1 Created 0.0s

✔ Container roots-back-mysql-1 Created 0.0s

✔ Container roots-back-application-1 Created

```

But then when I start the containers, their output logs are missing the `roots-back-` project name prefix.

```
selenium-1 | 2024-07-01 05:00:43,753 CRIT Server 'unix_http_server' running

selenium-1 | 2024-07-01 05:00:43,753 INFO supervisord started with pid 7

application-1 | 2024-07-01 05:00:43,888 INFO Set uid to user 0 succeeded

application-1 | 2024-07-01 05:00:43,889 INFO supervisord started with pid 1

mysql-1 | 2024-07-01T05:00:43.901656Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1

mysql-1 | 2024-07-01T05:00:43.907482Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
```

This used to include the project name by default before, but seems to have changed after a Docker Desktop update for OSX.

Any idea how I can get this configured properly again?

Thanks for your help

🌐
Medium
medium.com › @atige.mihan › project-name-in-docker-compose-f53c53bdb41d
Project name in docker-compose. Most of the times, we run our… | by Aref Khandan | Medium
June 20, 2022 - Most of the times, we run our ‘docker-compose up’ command from the same directory as before, but once for any reason, you change the name of the directory which your ‘docker-compose.yml’ file resides in, you’ll find out that docker-compose commands like ‘docker-compose ps’ return empty output. ... This phenomena is because of docker-compose ‘COMPOSE_PROJECT_NAME’ variable which could be passed by -p switch.