Docker Compose for Beginners: Your First Stack in 15 Minutes
Learn Docker Compose from scratch and deploy your first multi-container application in just 15 minutes. Perfect for homelab beginners.
Posted by
Related reading
Private Cloud vs Public Cloud: When to Self-Host and When Not To
Understand when self-hosting makes sense and when public cloud is better. A practical guide to choosing between private cloud homelab and AWS/GCP/Azure services.
Homelab Documentation: Wiki.js vs BookStack for Self-Hosted Wikis
Document your homelab setup with self-hosted wikis. Compare Wiki.js and BookStack for creating searchable documentation of your infrastructure and procedures.
Docker Security Scanning: Trivy and Dockle for Safe Containers
Scan your Docker images for vulnerabilities before deploying. Learn to use Trivy and Dockle to secure your self-hosted homelab container infrastructure.

What is Docker Compose?
Docker Compose is the secret weapon of every homelab enthusiast. It allows you to define and run multi-container applications with a single YAML file. Instead of running multiple complex docker commands, you describe your entire stack in one file and launch it with one command.
Think of Docker Compose as a recipe book for your applications. You write down all the ingredients (containers), how they connect (networks), and where they store data (volumes) - then Compose handles the rest.
Prerequisites
Before we start, make sure you have Docker and Docker Compose installed. On most modern systems, Docker Compose comes bundled with Docker Desktop or can be installed as a plugin.
# Check if Docker is installed docker --version # Check if Docker Compose is installed docker compose version
If you see version numbers for both commands, you're ready to go. If not, visit the official Docker documentation to install Docker for your operating system.
Understanding the docker-compose.yml File
Every Docker Compose project starts with a docker-compose.yml file. This file uses YAML syntax to define your services, networks, and volumes.
version: "3.8"
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html
restart: unless-stopped
database:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: myapp
volumes:
- db_data:/var/lib/mysql
restart: unless-stopped
volumes:
db_data:Key Components:
- version: The Compose file format version
- services: The containers that make up your application
- volumes: Persistent storage that survives container restarts
- networks: How containers communicate (auto-created by default)
Your First Stack: WordPress in 5 Minutes
Let's deploy a complete WordPress site with a MySQL database. Create a new directory and add this docker-compose.yml file:
version: "3.8"
services:
wordpress:
image: wordpress:latest
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress_data:/var/www/html
depends_on:
- db
restart: unless-stopped
db:
image: mysql:8.0
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
- db_data:/var/lib/mysql
restart: unless-stopped
volumes:
wordpress_data:
db_data:Essential Docker Compose Commands
Navigate to the directory containing your docker-compose.yml and use these commands:
# Start all services in the background docker compose up -d # View running containers docker compose ps # View logs from all services docker compose logs -f # Stop all services docker compose down # Stop and remove all data (careful!) docker compose down -v
After running docker compose up -d, visit http://localhost:8080 to see your WordPress site!
Best Practices for Homelab
- Always use restart policies: Add
restart: unless-stoppedto ensure services start after reboots - Use named volumes: Named volumes are easier to manage and backup than bind mounts
- Set resource limits: Prevent runaway containers from consuming all system resources
- Use .env files: Store sensitive data like passwords in .env files, not in the compose file
- Version your compose files: Keep them in Git for easy rollback and documentation
Next Steps
Congratulations! You've just deployed your first Docker Compose stack. From here, the possibilities are endless. You can deploy media servers, password managers, file storage, and dozens of other self-hosted services using the same principles.
The key to mastering Docker Compose is practice. Start with simple stacks and gradually add more complexity as you become comfortable with the concepts.
