Skip to main content

Company in a Box, Part 2 of 11: One Compose file to run the whole company

A series on building a company's IT with containers and open source

When people see the lab's docker-compose.yml, they usually scroll for a while, go quiet, and then ask: "Why isn't this split up?"

Fair question. It's a long file. It has the scroll bar of a Terms of Service page.

But one file, one project and one network is the best decision I made in the whole lab. Let me explain before you close the tab.

One project, one network

Everything runs in a single Compose project, home-lab, on one network, home-lab-net. That gets me three things for free.

Every service can reach every other one by name. Grafana talks to zabbix-web. Keycloak talks to postgres. Apps send mail to mailserver:25. There isn't a single IP address in the configuration, which is exactly how many IP addresses I want to remember.

One command shows everything:

docker compose -p home-lab ps

One command applies everything:

docker compose -p home-lab up -d --remove-orphans

Delete a service from the file, and the next deploy removes it from the host. No orphaned containers haunting the place.

The repository is small:

lab/
└── home-lab/
    ├── docs/home-lab-handbook.md      the ONLY lab document
    └── docker/
        ├── docker-compose.yml         every service
        ├── .env.example               template for the secrets file
        ├── scripts/                   bootstrap, configure-*, repair-*
        ├── deploy/hatchery/           the automation
        ├── patched/                   locally patched images
        └── <app>/                     per-app config

Note "the ONLY lab document". I started with a README per app. They drifted apart, contradicted each other, and eventually I trusted them about as much as a vendor's "this update requires no restart". Now there's one handbook, and changing the lab means changing the handbook in the same commit.

YAML anchors: copy-paste, but respectable

Seventy services share a lot of settings. YAML anchors let you write them once:

x-hardening: &hardening
  security_opt:
    - no-new-privileges:true
  pids_limit: 1024
  grafana:
    <<: *hardening
    mem_limit: 2g

Every service merges that block. Every service also gets a memory limit of about twice what it normally uses.

That sounds like bureaucracy until the day one container goes rogue. Without limits, one misbehaving app eats the whole Docker VM and takes everyone with it. With limits, it suffers alone, as nature intended.

(Spoiler for post 8: limits can also be too tight, and that's how I met Grafana at 1000% CPU.)

Two databases, not twenty-five

Most vendor Compose files come with their own database container. With 25+ apps, that's 25 database servers to patch, tune and back up. No thank you.

Instead, there are two:

  • MariaDB for the PHP gang: Drupal, Nextcloud, iTop, Matomo, HumHub, Moodle, LimeSurvey, EspoCRM.
  • PostgreSQL for everyone else: Keycloak, Zabbix, Grafana, SonarQube, n8n, LiteLLM, Sympa, Plane.

A script, bootstrap-databases.ps1, creates every database and user and reconciles passwords with the secrets file on every start. It never drops anything. When an app says "database unreachable", running that script is step one, and usually also the last step.

There are exceptions. GitLab uses its own bundled PostgreSQL, because it wanted a newer major version than the shared server runs. That's fine. The rule is "share by default", not "share or die".

One .env to rule them all

Every setting and every secret lives in one file: home-lab/docker/.env. Git ignores it. The committed .env.example is the template.

The Compose file has no password fallbacks. If a variable is missing, this fails before anything starts:

docker compose -p home-lab config -q   # silence is golden

The trick that makes this bearable is a script called ensure-app-secrets.ps1. Values left blank in the template (database passwords, OIDC secrets, API keys, encryption keys) are generated on first start and on every deploy. It only fills blank values, so it never overwrites anything.

Adding an app with five new secrets means adding five empty lines to the template. The next deploy fills them in. I haven't typed a password in months, and I don't miss it.

Two rules I learned the expensive way:

Some keys can never change. Grafana's secret key, n8n's encryption key, LiteLLM's salt key: they encrypt data already stored. "Rotate" one, and you get to meet your data again in its new, unreadable form.

Admin passwords are first-run only. Almost every app reads its ADMIN_PASSWORD exactly once: when it creates the account on an empty volume. Change .env later and the app politely ignores you. The handbook now has a table with the reset command for every app, because I needed every single one of them. Some twice.

Configuration is a script, or it didn't happen

Containers handle installation. They don't handle "connect Nextcloud to the office server", "create the Keycloak clients" or "set Moodle's sender address". In VM-land, that's an afternoon of clicking through admin consoles and a promise to document it later. (You won't. I didn't.)

Here, each of those is a configure-*.ps1 script that uses the app's API or CLI:

Script Does
configure-keycloak.ps1 Realm, groups, every OIDC/SAML client, SMTP
configure-app-auth.ps1 Tells each app to sign in through Keycloak
configure-mail.ps1 Mail server, relay rules, every app's sender
configure-zabbix-monitoring.ps1 Hosts, checks, alerting
configure-proxy-hosts.ps1 Trusted domains and proxies

There are about thirty. Every one of them is:

  1. Idempotent. Run it once or a hundred times, same result.
  2. Run on every start, after docker compose up.
  3. Self-documenting, through PowerShell's Get-Help.

So the lab heals itself toward whatever is in Git. Change something in a web UI, and the next deploy quietly puts it back. That annoyed me exactly once. Now I'd fight anyone who tried to take it away.

One gotcha: some images reapply their own settings from environment variables in the entrypoint, on every start. Moodle's did that with its mail settings. My script set them, the nightly rebuild restarted Moodle, the entrypoint overwrote them, and Moodle went back to sending mail as someone else. If a setting "reverts by itself", read the image's entrypoint before you accuse your own script. Your script is probably innocent. This time.

Squeezing a company into 32 GB

Here's a confession: I'm slightly obsessed with resource usage. Every container is on probation, and every megabyte has to justify itself. Seventy containers, a local AI stack and a GitLab on a 32 GB desktop is a game of Tetris that never ends, and I'm weirdly happy playing it.

The moves that made the biggest difference:

  • Memory limits from real data. Each limit is about twice what the container actually uses, measured, not guessed. Too generous wastes RAM; too tight, and you get the Grafana story in post 8.
  • Two shared database servers instead of twenty-five private ones. Probably the single biggest saving in the lab.
  • Taming the heavyweights. GitLab is capped at 4 GB: two Puma workers, Sidekiq concurrency 10, its built-in Prometheus switched off. ClickHouse runs a low-resource config. Cognee is limited to 10 AI calls a minute so the GPU isn't monopolised.
  • Kernel tuning on every start. Docker Desktop resets its VM's settings on boot, so the start script sets vm.swappiness=10 (fewer pointless swap storms) and vm.max_map_count (SonarQube's Elasticsearch insists) every single time.
  • Retention with a budget. Logs and metrics keep 30 days, traces 31 days (about 1 GB), and each container's own log is capped at 20 MB × 5. Watchtower deletes superseded images. Nothing grows forever.
  • Replacing fat with lean. Greenbone's ~57 GB of volumes became a scanner container measured in megabytes. Two database admin tools became one. Dremio's 5 GB of Java became Trino and Superset.
  • The GPU stays on the host. Ollama runs natively on Windows, so the models get the GPU directly instead of fighting through another layer.

Optimising is never "done". Zabbix and Grafana tell me where the memory and CPU are going, and every few weeks something gets trimmed, tuned or replaced.

Adding a service, in five steps

  1. Add it to docker-compose.yml, with its Traefik labels.
  2. Add a DNS record to the zone file.
  3. Add its secrets as blank lines to .env.example.
  4. Add its Keycloak client and sign-in settings to the configure scripts.
  5. Push to main.

Step 5 deploys it. No step involves RDP.

Next: how a request actually finds its way in, featuring four reverse proxies, a DNS server, a VPN and a tunnel.

Read next: Company in a Box, Part 3 of 11: Private by default, public by exception

Comments

Popular posts from this blog

Company in a Box, Part 1 of 11: Why I'm building a company's IT with containers and open source

A series on building a company's IT with containers and open source Hi. I'm an IT admin. I've been doing this long enough to have strong opinions about Group Policy and long enough to have strong feelings about printers. For most of my career, my home lab looked exactly like my day job: a Hyper-V host and a handful of VMs. Each one had its own OS to patch, its own disk to grow, its own backup job, and its own creative way of breaking at 2 a.m. It worked. It also stopped teaching me anything. These days every vendor README starts with docker compose up , and I was still out here lovingly hand-crafting a VM for each one, like a medieval monk illuminating manuscripts. So I moved the lab to containers. Then things got slightly out of hand. A confession about who I am Let's get this out of the way, because it explains every decision in this series. I'm a Microsoft guy. Windows Server, Active Directory, Exchange, Hyper-V: that's my day job, and I'm good at...

Company in a Box, Part 11 of 11: What it costs vs. SaaS and the cloud

A series on building a company's IT with containers and open source Ten posts in, it's time for the question everyone skips to: is this worth it? Inner Bits runs a small company's IT on one desktop. What does that cost? What would the same company pay to rent it all as SaaS? And what if you ran the exact same stack on a rented server at Hetzner, OVH, Azure or AWS instead of under your desk? Get comfortable, there are tables. Three of them. What the lab costs to run All prices are what I pay in Portugal. Item Cost Hardware a ~€1,500 desktop (32 GB RAM, a GPU for the AI models); over five years, ~€25 a month Electricity ~€15–30 a month Domain name ~€1 a month (about €12 a year) Cloudflare ~€5 a month (Workers Paid; Tunnel, Email Routing and DNS are free) Stalwart Enterprise licence paid (see the ledger below) Tailscale free personal plan Software €0 for everything else. Every app is free software or a free community edition Total ro...

Company in a Box, Part 9 of 11: Patched images and vulnerability scanning

A series on building a company's IT with containers and open source Running a company's IT means running its security too. A home lab is an easy place to skip that. "It's just at home." "It's behind the VPN." Famous last words, usually followed by a very educational weekend. Inner Bits has a public website, inbound mail and a tunnel from the internet. It's meant to show what a small company could run. So it gets the treatment I'd expect at work: hardened containers, patched images, and scanning that happens whether I remember it or not. The baseline: same rules for everyone Every service in the Compose file merges a shared hardening block: no-new-privileges , so a process can't climb its way up through setuid binaries; a PID limit , so a fork bomb only blows up its own container; a memory limit of about twice normal use. On top of that: healthchecks on the databases and key services, databases never recreated unattended, and se...