DEV Community

Antonio Mancini
Antonio Mancini

Posted on • Originally published at dev.antomanc.com

πŸš€ Why Docker Compose is the right tool for your home lab πŸ§ͺ

If you’re asking yourself

πŸ€” "How should I run applications in my home lab?"

🀨 "Is Docker Compose the right tool for my home lab?"

😫 "How can I manage multiple containers without losing my mind?"

Then you are in the right place.

In this post, I will explain why Docker Compose can be your new best friend, and how to get started with it in the right way.


🐳 What is Docker?

Docker is a platform that run and manage applications using containerization. Containers are boxes that include your app and all of its dependencies.

Have you ever heard of the phrase

😭"But it works on my machine"

Maybe the person who said it was not inventing excuses. The next time you hear it, show them Docker.


🧩 What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can use a simple YAML file to describe your entire application services in one place.
It’s declarative β€” meaning you say what you want, not how to do it.


πŸ†š Declarative vs Imperative

Let's say you want to run a web server and a database.
With the imperative approach, you do this:

docker run -d --name webserver -p 80:80 nginx
docker run -d --name database -e MYSQL_ROOT_PASSWORD=root -d mysql
Enter fullscreen mode Exit fullscreen mode

This is fine... until you forget what you did. And imagine doing that for 20 containers, each with its own configuration and dependencies 😡.
With Docker Compose instead, aka the declarative approach:

services:
  webserver:
    image: nginx
    ports:
      - "80:80"
  database:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
Enter fullscreen mode Exit fullscreen mode

Now we are talking!

Easy to read, easy to write, and easy to maintain.

You just run docker-compose up and you can go have a coffee while Docker Compose does its magic.


🌱 OUT OF TOPIC: A fully declarative Operating System?!

If you are reading this post and thinking

😐 "Whoa, this declarative stuff is amazing..." 😐

(Yes, I know β€” I'm probably the only one getting hyped about this stuff πŸ˜…)

Then you should definitely check out NixOS. It’s a Linux distro where everything is declared in a config file: packages, users, services, even your desktop environment.

πŸͺ„ It’s like Docker Compose, but for your whole OS.
Not for the faint of heart, but it's worth considering for your next distro hop.


πŸ› οΈ Getting started with Docker Compose

Step 1: Install Docker and Docker Compose πŸ§‘β€πŸ’»

➑️ Official install guide

Step 2: Create your first docker-compose.yml

➑️ Define services, networks, volumes.

➑️ Run: docker-compose up

➑️ Sit back

For everything else:

➑️ Read the docs

🏠 Home lab use cases

Here’s a project structure you can use:

πŸ“`your-home-lab/
└── πŸ“`your-home-lab-docker-services/
    β”œβ”€β”€ πŸ“`your-blog/
    β”‚   └── πŸ“„`docker-compose.yml
    β”œβ”€β”€ πŸ“`your-password-manager/
    β”‚   └── πŸ“„`docker-compose.yml
    β”œβ”€β”€ πŸ“`your-media-server/
    β”‚   └── πŸ“„`docker-compose.yml
    └── πŸ“`your-other-service/
        └── πŸ“„`docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Keep each service separate, keep your sanity intact.
Use Git to version control each one.

You could also put everything into a single docker-compose.yml file β€”

but unless you're a big fan of Italian recipes like spaghetti YAML 🍝,

I strongly recommend keeping things modular.


🏁 Final thoughts

Docker Compose is a great first step into the world of reproducible, manageable infrastructure, perfect for home labs and small projects that doesn't require the scale and complexity of tools like Kubernetes 😨

Top comments (0)