🧩
Container Platform

Docker Compose

Define and run multi-container Docker applications with a single YAML file

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Docker Compose runs multiple containers (app + database + cache) with one simple command.

📁

Config files for Docker Compose

Where to create or edit the main configuration — paths below match the setup steps.

  • docker-compose.yml

    Location: Project root (or -f path)

    Services, networks, volumes, and env for multi-container apps

  • .env

    Location: Same directory as compose file

    Variable substitution for compose (optional)

📥

Step 01

Install Docker Compose

(01)Install (included with Docker Desktop)

Docker Compose V2 is bundled as the docker compose plugin.

Linux
1# Ubuntu / Debian (plugin)
2sudo apt-get update
3sudo apt-get install -y docker-compose-plugin
4
5# Standalone (legacy)
6sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
7sudo chmod +x /usr/local/bin/docker-compose

Step 02

Verify

(01)Version

Linux
1docker compose version

Step 03

Manage Compose Stacks

(01)Lifecycle commands

Linux
1docker compose up -d # start in background
2docker compose ps # list services
3docker compose logs -f api # follow logs
4docker compose restart api
5docker compose down # stop & remove
6docker compose down -v # also remove volumes
7docker compose build --no-cache # rebuild images

📋Config templates

10 YAML templates for Docker Compose. Copy and deploy after setup.

10 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

docker-compose.yaml

PostgreSQL database + Flask app with env file and volume persistence

yaml
1version: "3.9"
2
3services:
4 db:
5 image: postgres:15-alpine
6 environment:
7 POSTGRES_DB: dukaan_db
8 POSTGRES_USER: dukaan
9 POSTGRES_PASSWORD: dukaan123
10 ports:
11 - "5432:5432"
12 volumes:
13 - pgdata:/var/lib/postgresql/data
14
15 app:
16 build: .
17 ports:
18 - "5000:5000"
19 env_file:
20 - .env
21 depends_on:
22 - db
23
24volumes:
25 pgdata:

Dockerfile

Flask application container image

dockerfile
1FROM python:3.12-slim
2WORKDIR /app
3COPY requirements.txt .
4RUN pip install --no-cache-dir -r requirements.txt
5COPY . .
6EXPOSE 5000
7CMD ["python", "app.py"]
📄

Step 01

Run with Docker Compose

(01)Build and start services

Linux
1cd your-project/
2docker compose up -d --build
3docker compose ps
4docker compose logs -f app

(02)Stop and clean up

Linux
1docker compose down
2docker compose down -v # remove volumes