Compose names the containers, networks and volumes of a stack after a project name, and by default that name is the folder the compose file sits in. Two checkouts in folders with the same name look like one project.
Set the name in the file itself:
name: storefront
services:
web:
image: nginx:stable
Compose picks the project name in this order, highest first:
- the
-pflag - the
COMPOSE_PROJECT_NAMEenvironment variable - the top-level
name: - the folder that holds the compose file
- the current folder, when no compose file is given
So name: gives the stack a stable default, and -p still wins when you want a second copy next to it:
docker compose -p storefront-test up -d
The name is the prefix of what Compose creates, for example storefront-web-1 for the container and storefront_default for the network. Two projects with the same name get in each other’s way for that reason.
Caveat: renaming the project later does not rename what already exists. Compose sees new containers and volumes under the new name, and the old ones stay behind. Pick the name before the first up, and use docker compose ls to see which projects Compose knows about.
Further reading: Specify a project name
Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more