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
🌐
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 ...
🌐
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.
Find elsewhere
🌐
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
🌐
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
🌐
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
🌐
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.
🌐
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
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.

🌐
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 - export COMPOSE_PROJECT_NAME=my-project docker-compose up ... You can also set the COMPOSE_PROJECT_NAME environment variable in an environment file.