<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu" -->

---
title: Introduction to Docker Compose | daily.dev
description: A practical walkthrough of Docker Compose covering how to define multi-container applications in a single compose.yaml file, using a Node.js app plus Postgres...
canonical: https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Introduction to Docker Compose | daily.dev
og:description: A practical walkthrough of Docker Compose covering how to define multi-container applications in a single compose.yaml file, using a Node.js app plus Postgres...
og:url: https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu
og:image: https://api.daily.dev/og/posts/AuQwYAjLu.png
og:image:alt: Introduction to Docker Compose
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to Docker Compose

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 7 min read · 11 upvotes · 0 comments

## Summary

A practical walkthrough of Docker Compose covering how to define multi-container applications in a single compose.yaml file, using a Node.js app plus Postgres database as the running example. Topics include services, ports, volumes, health checks, environment variable interpolation, bind mounts for development, override files, one-off commands (run vs exec), and common mistakes such as using localhost instead of service names or assuming start order guarantees readiness. Includes the author's personal heuristics for when Compose is worth adopting.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/docker-compose>

## Questions this post answers

### Why can't my Node app connect to Postgres using localhost inside Docker Compose?

Localhost inside a container refers to that container itself, not the host machine or another container. Since Postgres runs in a separate container, the app must connect using the service name defined in compose.yaml, such as db, along with the container port 5432, because Compose creates an internal DNS network resolving service names to the right containers.

_Developers debugging container networking issues can find focused Docker Compose fixes on daily.dev._

### Does depends_on in Docker Compose wait for a database to be ready before starting the app?

No, the short depends_on syntax only controls container start order, not readiness. A Postgres container can be running but not yet accepting connections. Adding a healthcheck with condition: service_healthy, such as pg_isready, tells Compose to wait until the database actually accepts connections before starting the dependent service.

_Anyone wiring up service startup order in Compose can compare healthcheck patterns on daily.dev._

### What happens to my database data when I run docker compose down -v?

Running docker compose down -v removes containers along with named volumes, which deletes persistent data such as a Postgres pgdata volume. Without the -v flag, docker compose down only removes containers and the default network, leaving named volumes and their data intact for the next docker compose up.

_Teams relying on Compose volumes for local data can track these gotchas on daily.dev before wiping a database._

## Similar posts on daily.dev

- [How to Use to Docker with Node.js: A Handbook for Developers](https://daily.dev/posts/how-to-use-to-docker-with-node-js-a-handbook-for-developers-ivekxfkrx) · freeCodeCamp · 9 upvotes · 0 comments
- [Docker Basics for Beginners: The Concepts You Actually Need First](https://daily.dev/posts/docker-basics-for-beginners-the-concepts-you-actually-need-first-l4gbbdww8) · Medium · 2 upvotes · 1 comments
- [Docker Compose is the only self-hosting skill you actually need to learn properly](https://daily.dev/posts/docker-compose-is-the-only-self-hosting-skill-you-actually-need-to-learn-properly-muiflazjx) · XDA Developers · 9 upvotes · 1 comments
- [Docker Explained: A Practical Guide to Containers for Developers](https://daily.dev/posts/docker-explained-a-practical-guide-to-containers-for-developers-simj4vyth) · JS Dev Space · 12 upvotes · 1 comments

---

Tags: [#nodejs](https://daily.dev/tags/nodejs), [#docker](https://daily.dev/tags/docker), [#postgresql](https://daily.dev/tags/postgresql), [#containers](https://daily.dev/tags/containers), [#docker-compose](https://daily.dev/tags/docker-compose)

[View this post on daily.dev](https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Introduction to Docker Compose","url":"https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu"},"datePublished":"2026-08-28T05:26:00.667Z","dateModified":"2026-09-14T08:22:33.331Z","description":"A practical walkthrough of Docker Compose covering how to define multi-container applications in a single compose.yaml file, using a Node.js app plus Postgres...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/18b92df4ff3dd8f4e6d6eedcb6af4e44?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/18b92df4ff3dd8f4e6d6eedcb6af4e44?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":11},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"nodejs,docker,postgresql,containers,docker-compose","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Introduction to Docker Compose"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/introduction-to-docker-compose-auqwyajlu#faq","mainEntity":[{"@type":"Question","name":"Why can't my Node app connect to Postgres using localhost inside Docker Compose?","acceptedAnswer":{"@type":"Answer","text":"Localhost inside a container refers to that container itself, not the host machine or another container. Since Postgres runs in a separate container, the app must connect using the service name defined in compose.yaml, such as db, along with the container port 5432, because Compose creates an internal DNS network resolving service names to the right containers. Developers debugging container networking issues can find focused Docker Compose fixes on daily.dev."}},{"@type":"Question","name":"Does depends_on in Docker Compose wait for a database to be ready before starting the app?","acceptedAnswer":{"@type":"Answer","text":"No, the short depends_on syntax only controls container start order, not readiness. A Postgres container can be running but not yet accepting connections. Adding a healthcheck with condition: service_healthy, such as pg_isready, tells Compose to wait until the database actually accepts connections before starting the dependent service. Anyone wiring up service startup order in Compose can compare healthcheck patterns on daily.dev."}},{"@type":"Question","name":"What happens to my database data when I run docker compose down -v?","acceptedAnswer":{"@type":"Answer","text":"Running docker compose down -v removes containers along with named volumes, which deletes persistent data such as a Postgres pgdata volume. Without the -v flag, docker compose down only removes containers and the default network, leaving named volumes and their data intact for the next docker compose up. Teams relying on Compose volumes for local data can track these gotchas on daily.dev before wiping a database."}}]}
```

