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. The default project name is the basename of the current directory.
Here are some of the reasons why you might want to change the composer project name:
- To avoid conflicts with other projects: If you have multiple projects running on the same Docker host, you may want to give each project a unique name to avoid conflicts with container names.
- To have a more human-readable name: The default project name may be too long or difficult to remember. You can use a shorter or more meaningful name for your project.
There are 3 ways to change the compose project name:
1. Use the -p
flag:
You can use the -p
flag to specify the project name on the command line. For example, to change the project name to my-project
, you would run the following command:
docker-compose -p my-project up
2. Use the COMPOSE_PROJECT_NAME
environment variable:
You can also set the COMPOSE_PROJECT_NAME
environment variable before running the docker-compose up
command. For example, to change the project name to my-project
, you would run the following command:
export COMPOSE_PROJECT_NAME=my-project
docker-compose up
3. Use an environment file:
You can also set the COMPOSE_PROJECT_NAME
environment variable in an environment file. For example, create a file named .env
in the root directory of your project and add the following line to it:
COMPOSE_PROJECT_NAME=my-project
Then, you can run the docker-compose up
command without setting the environment variable explicitly.
Once you have changed the composer project name, you will need to restart any containers that are currently running.
🔍. Similar posts
The Simple Way to Run a Long Docker Command in Multiline
14 Jan 2025
How to Hard Reset Your Git Repository to 10 Minutes Ago
04 Sep 2024
How to Easily Generate a Java Project Using Maven Command
04 Sep 2024