Running multiple projects using docker which each runs with docker-compose
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
You can run multiple Compose-based projects on the same machine as long as their containers, networks, volumes, and host ports do not collide. In practice, Docker Compose already gives you most of the isolation you need, because each project gets its own Compose project name and resource prefix.
How Compose Separates Projects
When you run docker compose up in different directories, Compose usually uses the directory name as the project name. That project name is then used to namespace resources such as networks and containers.
For example, two directories might produce resources like:
- '
projecta_web_1' - '
projectb_web_1'
That prevents most conflicts automatically, even if both projects have services with the same names in their compose.yaml files.
A Typical Workflow
Imagine two projects:
Each one has its own Compose file. You can start them independently:
If the services use different host ports, both projects can run at the same time without trouble.
The Main Real-World Conflict: Host Ports
Compose project names isolate container names and networks, but they do not magically solve host port conflicts. If both projects publish 8080:8080, only one of them can bind port 8080 on the host.
Example:
The second project should use a different host port such as 8081, 8082, or another free port.
Use Explicit Project Names When Needed
If you want more control than the directory name provides, set the project name explicitly with -p or COMPOSE_PROJECT_NAME.
This is useful in CI, in temporary environments, or when multiple clones of the same repository run on one machine.
Inspect and Manage Each Project Separately
Once several stacks are running, it helps to query them by project name so you can see exactly which containers belong to which app.
The same rule applies when stopping or removing them. Use the same project name or directory context that you used on startup so you do not accidentally operate on the wrong stack. That keeps day-to-day cleanup predictable. It reduces operator mistakes.
Volumes and Networks Still Need Thought
Compose prefixes named volumes and networks with the project name, which helps a lot. But if you deliberately configure external volumes or hard-code shared network names, you can still create collisions or accidental cross-project communication.
For most local development setups, the safest rule is simple:
- Let each project keep its own default network
- Use project-scoped named volumes unless shared data is intentional
Common Pitfalls
- The most common failure is port collision, not container-name collision.
- Running multiple copies of the same repository from directories with the same effective project name can cause resource overlap unless you set
-p. - External volumes and shared networks bypass some of Compose's built-in isolation.
- Remember to stop the right project with the same directory or project name you used to start it.
Summary
- Multiple Compose projects can run side by side on one machine.
- Compose usually isolates them automatically through project names based on directory names.
- Host ports must still be unique across projects.
- Use
-porCOMPOSE_PROJECT_NAMEwhen you need explicit, predictable separation.
Related reading
- running nvidia-docker on Windows 10 WSL2
- SASL authentication in docker zookeeper and kafka
- Scalable spring batch job on kubernetes
- Scale down Kubernetes Pods
- seccompunconfined for a container in a kubernetes pod? Or changing default in docker 1.10?
- See full command of running/stopped container in Docker
- SELinux is not supported with the overlay graph driver
- sending udp broadcast from a docker container

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.