COMPOSE_PROJECT_NAME
Sets the project name for Docker Compose, which is used as a prefix for container names, network names, and volume names. Defaults to the directory name containing the compose file. Useful for running multiple instances of the same compose setup.
Last updated:
COMPOSE_PROJECT_NAME is the prefix Docker Compose puts on every container, network, and volume it creates — `myapp-web-1`, `myapp_default`, `myapp_db-data`. By default it is the lowercased name of the directory holding your compose file, which is why two checkouts in folders both called 'app' collide, and why renaming a folder orphans the old containers and volumes. Set it explicitly to run several isolated copies of the same stack side by side (e.g. per-branch CI environments) or to keep names stable regardless of directory.
- Provider
- Docker
- Category
- compose
- Set by
- Set via environment variable or the -p flag on docker compose commands
- Example
- myapp-dev
How to set COMPOSE_PROJECT_NAME
bash
export COMPOSE_PROJECT_NAME=myapp-pr-42
docker compose up -d.env file (auto-loaded by Compose)
COMPOSE_PROJECT_NAME=myapp-devequivalent CLI flag
docker compose -p myapp-pr-42 up -dReferences
Frequently Asked Questions
Why did my Compose database lose its data after I renamed the folder?
It did not — the data is in a named volume prefixed with the old COMPOSE_PROJECT_NAME (the previous folder name). Renaming the directory changes the project name, so Compose creates fresh volumes and the old ones are orphaned. Run `docker volume ls` to find the old prefix, or pin COMPOSE_PROJECT_NAME so the name never depends on the directory.
Stay up to date
Get notified about new guides, tools, and cheatsheets.