If you are into self hosting, initially you might have asked yourself:
- How should I run my applications?
- How can I manage all my services in a clean way?
This post explains why Docker Compose can be the right answer for your home lab and small self hosted environments.
What is Docker?
Docker is a platform that allows you to run applications using containers.
A container packages an application with everything it needs to run:
- Dependencies
- Runtime
- Configuration
- System libraries
So it can run everywhere in a consistent way.
This is what put an end to the classic problem “it works on my machine”. if it works inside the container on your machine, it works anywhere the container can run.
What is Docker Compose?
Docker Compose is a tool to define and run multi container applications.
Instead of starting containers manually with long docker run commands, you describe your applications using a single YAML file.
This file declares:
- Which services you want to run
- Which images they use
- How they communicate with each other
- Which volumes they need
Docker Compose follows a declarative approach: you describe the desired state, and Docker runs it consistently every time.
Declarative vs Imperative
Suppose you want to run a web server and a database.
With an imperative approach, you would run commands manually like this:
docker run -d --name webserver -p 80:80 nginx
docker run -d --name database -e MYSQL_ROOT_PASSWORD=root mysql
This works, but it doesn’t scale well. You will forget commands and parameters and make mistakes over time. Now compare that to Docker Compose:
services:
webserver:
image: nginx
ports:
- "80:80"
database:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
The configuration is readable, you can version it using Git and share it easily.
You can run the entire setup with this command:
docker compose up
This is one of the biggest reasons why Compose is well suited for home labs.
A fun fact on declarative systems
If you like the idea of declarative configurations, you should know that the same idea applies to much more things than just containers.
NixOS is a Linux distribution where the entire system is defined declaratively: packages, users, services, and even the desktop environment.
It’s not beginner friendly for sure, but it’s very similar to Docker Compose conceptually.
Getting started with Docker Compose
The steps are easy:
-
Install Docker and Docker Compose
→ https://docs.docker.com/engine/install/ -
Create a
docker-compose.yamlfile
Define services, networks, and volumes. -
Start everything up with:
docker compose up
Then the official documentation is a nice place to learn and troubleshoot: https://docs.docker.com/compose/
Example Home lab project structure
A clean defined structure makes a huge difference over time.
A simple and effective approach is to keep one Compose file per service:
your-home-lab/
└── docker-services/
├── blog/
│ └── docker-compose.yml
├── password-manager/
│ └── docker-compose.yml
├── media-server/
│ └── docker-compose.yml
└── other-service/
└── docker-compose.yml
This approach has many advantages:
- Services are isolated and easier to reason about
- You can version each setup with Git
You can put everything into a single Compose file, but as the number of services grows, that file becomes nearly impossible to manage.
Final thoughts
Docker Compose is a perfect balance between simplicity and control.
For home labs, personal projects, and small servers, it’s often the best choice, without the complexity of orchestration systems like Kubernetes. Use those only when high availability and scaling are required.