Docker Compose for Developers: From Zero to a Working Stack in 30 Minutes

Docker Compose for Developers: From Zero to a Working Stack in 30 Minutes

Most developers meet Docker one container at a time: a database here, an app server there, a cache somewhere else, each started with its own long docker run command. It works until you need all of them at once, in the right order, on the same network, and a teammate asks how to run the project on their machine.

Docker Compose for developers solves exactly that problem. It lets you describe every service your app needs in a single YAML file, then start the whole stack with one command. No shell scripts to remember, no port numbers to look up, no “works on my machine” arguments. This guide takes you from an empty folder to a working stack with an app, a database, and a cache in about 30 minutes.

What Docker Compose actually does

Compose reads a file called compose.yaml (older projects use docker-compose.yml) and turns it into running containers. Each service in the file becomes one or more containers. Compose creates a private network for the stack, wires the services together so they can reach each other by name, and gives you a single set of commands to start, stop, rebuild, and tear down everything at once.

Without Compose, every developer keeps their own notes on which containers to start and in what order. With Compose, the setup lives in version control next to the code, and a new teammate runs two commands and has the same environment as everyone else. For the longer backstory, this guide to running multi-container apps locally with Docker Compose covers the basics in more depth.

The pieces: services, networks, and volumes

A Docker Compose file has three ideas worth learning first. A service is one piece of your stack: the web app, the database, or the cache. A network is the private channel services use to talk to each other. A volume is storage that survives when a container stops, which is how your database keeps its data between restarts.

Here is a complete compose.yaml for a small web app with a Postgres database and a Redis cache:

services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://app:secret@db:5432/appdb
    depends_on:
      - db
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=appdb
  cache:
    image: redis:7
volumes:
  pgdata:

Notice how the web service reaches the database: it uses the hostname db, which is just the service name. Compose handles the DNS on its private network, so no IP addresses to hardcode. The ports line maps port 3000 on your machine to port 3000 in the container, the only port you need to reach the app from a browser.

Docker Compose for developers: the 30-minute plan

Work through these steps in order. Each one builds on the last, and by the end you have a stack you can develop against.

Minutes 0-5: install and check

Install Docker Desktop on Mac or Windows, or Docker Engine plus the Compose plugin on Linux. Then run docker compose version and docker run hello-world. If both work, you are ready; if Compose is missing, check that your Docker install includes the compose plugin, which recent versions ship by default.

Minutes 5-15: write the compose file

Create a project folder with a small app: a Node.js Express app, a Python Flask app, or a static page served by Nginx. If you have not containerized an app before, start with containerizing a Node.js app with Docker and come back once you have a Dockerfile. Then write the compose.yaml from the previous section, adjusting the image names and port to match your app.

Minutes 15-20: start the stack and fix the first errors

Run docker compose up --build from the project folder. The first run downloads images and builds your app image, so it takes a few minutes. Read the logs: the most common first-run problems are a wrong port in the app code, a missing environment variable, and a database that is not ready when the app tries to connect. Fix them one at a time and rerun; Compose rebuilds only what changed.

Minutes 20-25: prove the pieces talk to each other

Open the app in a browser and confirm it loads. Then check the app can read and write the database: create one record through the app and read it back. Finally, confirm the cache answers with docker compose exec cache redis-cli ping, which should print PONG. If all three checks pass, the stack is real, not just running.

Minutes 25-30: make it survive a restart

Stop the stack with docker compose down, then start it again with docker compose up -d. Open the app and confirm the record you created is still there. That is the named volume doing its job. Without it, every restart would wipe the database, which is the most common surprise for people writing their first compose file.

The commands you will actually use

You only need a handful of Docker Compose commands day to day:

  • docker compose up -d starts the stack in the background.
  • docker compose down stops and removes containers and networks. Add -v only when you mean to delete volumes and their data too.
  • docker compose logs -f web follows the logs of one service.
  • docker compose exec web sh opens a shell inside the running web container.
  • docker compose ps shows which services are up and which ports they expose.
  • docker compose up --build rebuilds images after you change a Dockerfile or dependencies.

Two habits save time. While debugging, use docker compose up without -d, so logs stream to your terminal and Ctrl+C stops everything. At the end of the day, run docker compose down instead of leaving containers running; a clean start tomorrow beats a stale stack with a half-dead database.

Common mistakes and how to avoid them

Three mistakes cause most Compose headaches. The first is treating depends_on as a readiness check. It only controls start order, not whether the database accepts connections yet. Your app should retry its database connection on startup, or use a small wait script, instead of assuming the database is ready because its container started.

The second is putting data in the wrong place. A named volume like pgdata is the right home for database files, while a bind mount, which maps a folder on your machine into the container, suits source code you want to edit live. Mixing them up leads to slow file sync on some systems and permission errors on others. The full trade-off is covered in this comparison of Docker volumes versus bind mounts.

The third is tagging images as latest in a compose file you share with a team. Latest moves, so two developers can pull different images on different days and get different behavior. Pin a version, such as postgres:16 or redis:7, and change it deliberately when you mean to upgrade. Apply the same discipline to your own images: follow the best practices for a production-ready Dockerfile so the image builds the same way twice, and the compose file stops being a source of surprises.

Docker Compose vs Docker, and when to move on

Docker on its own runs one container at a time. Docker Compose coordinates several containers as one unit. That is the whole difference, and it is why Compose is the default for local development: an app is rarely one container, and the value is in the wiring between them.

Compose also has a ceiling. It runs on one machine, with no rolling updates or automatic restarts across hosts, and its scaling story ends at “run more copies of this service on this machine.” When you need several machines, health-based scaling, or zero-downtime deploys, look at Kubernetes or a managed container platform. That does not make Compose a toy: many teams run it in production on a single server for years, and many more use it only for local development while production lives elsewhere. Both are reasonable. The deciding factor is how much traffic and how many machines you actually have.

FAQ

Is Docker Compose free?

Yes. Docker Compose is open source and free to use. Docker Desktop, which most Mac and Windows developers install to get Docker and Compose, has a free tier for personal use, small businesses, and open-source work; larger companies should check official pricing.

Do I need a separate Dockerfile for each service?

Only for services built from your own code. Services that use a public image, such as Postgres or Redis, need just an image line in the compose file. The build line points Compose at a Dockerfile for the services you wrote yourself.

Can I use Compose for production?

You can, on a single server, and many small projects do. Keep secrets out of the compose file by loading them from an environment file, pin image versions, and set restart policies. When you outgrow one machine, move the workload to an orchestrator.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.