Docker Compose
- Aug 24, 2025
- 2 min read

What is Docker Compose ?
Docker Compose is a tool that allows you to define, configure, and run multi-container Docker applications using a single YAML file. With Compose, you can specify all your application’s services, networks, and storage volumes in one place and manage them together with simple commands, making it easier to develop, test, and deploy complex applications.
Why Use Docker Compose?
Simplifies Multi-Container Management: Instead of running multiple docker run commands, you can start your entire application stack with a single command.
Consistency Across Environments: Ensures your development, testing, and production environments are the same, reducing “it works on my machine” problems.
Faster Development Workflow: You can rebuild, start, stop, or scale services quickly without manually handling each container.
Easier Collaboration: Share the YAML file with your team so everyone can run the same stack easily.
Setups Node.js app with PostgreSQL using Docker Compose in minutes.
This guide works with any Node.js app that uses PostgreSQL, but you can use my example repository: XO-Game Example Repo
What You’ll Build
Universal setup – works with Express, NestJS, Fastify, etc.
PostgreSQL + Node.js with Docker Compose – run full stack locally in one command
Portable containers – run anywhere with Docker
Prerequisites (2 minutes setup)
Docker & Docker Compose installed locally
(Optional) Use the example repo:
Project Structure
Complete Docker Compose setup Guide
Step 1: Create Dockerfile
Step 2: Create docker-compose.yml
This is a Docker Compose configuration file (docker-compose.yml) for a simple XO Game application with a PostgreSQL database and a Node.js backend. Here's a breakdown of what it does:
1. Version
Specifies the Compose file format. Version 3.8 supports modern features like healthchecks, networks, and volume definitions.
Services
PostgreSQL Database
Runs a lightweight PostgreSQL 15 container.
Exposes port 5432 to your host for DB access.
Uses a named volume postgres_data to persist data.
Connects to the custom xo-network.
Healthcheck ensures the DB is ready before dependent services start.
Node.js Application
Builds your Node.js app from the local Dockerfile (build: .).
Exposes app port 8080 to host port 4000.
Environment variables configure DB connection.
depends_on ensures app waits until PostgreSQL is healthy.
Automatically restarts unless explicitly stopped.
4.Volumes
Named volume to persist PostgreSQL data between container restarts.
4. Networks
Creates a custom bridge network allowing app and postgres to communicate internally.
Step 4: Run Locally with Docker Compose
Your app will be available at: http://localhost:4000
PostgreSQL listens on: localhost:5432
Local Development & Testing
Start services:
Stop services:
Rebuild images:




