Orchestrate multi-container applications with ease. One file, one command.
Docker Compose is a tool designed to help you define and run multi-container Docker applications. With Compose, you use a YAML file to configure your application's services, networks, and volumes. Then, with a single command, you can create and start all the services from your configuration.
Imagine you have 5 microservices, a database, and a cache. Do you really want to run 7 different docker run commands every time you start work?
+ 5 more commands... hope you don't make a typo!
$ docker-compose upOne command to rule them all. Networks, volumes, and services created instantly in the correct order.
docker-compose updocker-compose -f docker-compose-development.yml upMost tutorials show you `docker run mongo` (pulling an existing image). but in real work, you clone a repository containing source code for a Frontend, Backend, and Database. Here is the evolution of setup:
This is exactly how you would define the setup for the scenario above. Notice how we link the user_app to the postgres service.
services:
postgres:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
user_app:
build:
context: ./
dockerfile: Dockerfile # <-- Uses the Prisma Dockerfile
environment:
DATABASE_URL: postgresql://postgres:mysecretpassword@postgres:5432/postgresdb
ports:
- 4000:4000
depends_on:
- postgres
volumes:
postgres_data:You might have noticed something missing: We defined two services (`postgres` and `user_app`), but we never created a Network! How do they talk to each other?
Fact: Docker Compose automatically creates a shared network for all services in the file.
Result: Services can communicate using their service names as hostnames.
(See? We use "postgres" instead of "localhost" or an IP address!)
Common Confusion: "If I change code, do I need to rebuild the image every time? That sounds slow!"
The Secret: You DO NOT rebuild every time. We use Volumes (Bind Mounts). Docker mirrors your local code folder into the container. When you save a file on your machine, it updates inside the container instantly, triggering hot-reload just like local dev.
Everyone on the team uses the exact same Node/Python/DB versions. No "works on my machine" bugs.
Don't pollute your laptop with 50 versions of Mongo, Redis, and Postgres. Delete container = Clean machine.
Your specific dev environment mimics the Linux server environment you'll deploy to.
(e.g., Simple Node.js app, Personal Portfolio, Learning)
(e.g., Microservices, Team Projects, Complex DBs)