Project names and independent copies
Read the Compose file
services: worker: image: busybox:1.37 pull_policy: never user: 10001:10001 network_mode: none command: - sh - -c - echo worker-ready; exec sleep 300Compose can derive a project name from the project directory, or take it from a top-level name, COMPOSE_PROJECT_NAME or the -p option. The CLI -p option has highest precedence. Use lowercase names starting with a lowercase letter or digit and containing lowercase letters, digits, hyphens or underscores. Here the same worker recipe is started as bm-v12-a and bm-v12-b. Containers belong to distinct project groups, but both use the same local image. Project names do not prevent collisions in explicitly shared resources or published host ports; neither is present in this lab. The full precedence is -p, COMPOSE_PROJECT_NAME, top-level name (last applicable file), project directory basename, then current directory basename when no file is specified. The project directory can be overridden.
Try it in a local lab
Manual lab only. Use a fresh approved disposable Linux VM with external network access blocked, local Docker Engine and modern Compose plugin. Check docker context show, docker version and docker compose version. Verify local BusyBox 1.37 image digest, native platform, inherited entrypoint, sh, sleep, wget and httpd where required, and writable /tmp for user 10001. Tags are mutable. Confirm every bm-v12 project and image tag is unused; review docker compose ls -a and project resources before mutation. For builds verify a local Buildx docker driver and preloaded base. No pulls, pushes, public ports, host mounts or real credentials. Check command/flag support locally; stop if missing. Run commands individually; unexpected failures mean stop, inspect and perform scoped cleanup. The negative probe is explicitly expected to fail. Dispose of the VM even if cleanup fails. Outputs are predictions, not recorded Docker runs. Before contacting Docker, verify the effective local endpoint including DOCKER_CONTEXT and DOCKER_HOST. Use a clean shell and reviewed fixture directory; check Compose environment overrides, .env, project labels and the resolved configuration. Explicit -f and -p select file and project, not the Engine. Run only on the approved VM; do not adopt existing resources.
Open lab-fixtures/docker-compose-fundamentals/07-project-names/ in the extracted archive. Work on a disposable copy and run the commands from that directory. The examples use the modern docker compose plugin, not legacy docker-compose.
docker compose -f compose.yaml -p bm-v12-a config --quietdocker compose -f compose.yaml -p bm-v12-b config --quietdocker compose -f compose.yaml -p bm-v12-a up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v12-b up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v12-a psdocker compose -f compose.yaml -p bm-v12-b psdocker compose -f compose.yaml -p bm-v12-a downdocker compose -f compose.yaml -p bm-v12-a ps -adocker compose -f compose.yaml -p bm-v12-b psExpect one running worker per project. Bringing down bm-v12-a should not remove bm-v12-b. Inspect both groups and clean up both independently. Check both project identities before down; verify A has no containers and B still has its original running worker ID.
Remove only the project resources you created. No volume deletion, force removal or global prune. Confirm no lab containers remain; the base image is retained.
docker compose -f compose.yaml -p bm-v12-a downdocker compose -f compose.yaml -p bm-v12-b downdocker compose -f compose.yaml -p bm-v12-a ps -adocker compose -f compose.yaml -p bm-v12-b ps -aCommon mistake
Running down without the same project selection may target a different project. Repeat the explicit -p and -f options in every command.
Manual practice
Explain which copy remains after bringing down A. Why could two independent projects still conflict if both publish the same host port?
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Project names and independent copies — Knowledge check
Apply the Compose concept to a new scenario.
Which option has highest project-name precedence?
Can two projects share the same image?
What can still collide across projects?