mithlond-public/OKF/guides/06-docker-deploy.md
Lukasz Boryn c12604ebb4 feat(template): publish the Mithlond self-hosted Gitea template
A spare-machine Gitea forge, hardened, backed up and with CI, as a template.
Personal values are placeholders listed in the README.
2026-10-16 15:04:18 +02:00

5.3 KiB

type, purpose, answers, cites
type purpose answers cites
Guide Bring up the Gitea and Caddy stack with automatic TLS.
How is the Docker Compose stack deployed?
compose.yml
Caddyfile

06 — Docker Deploy

Deploy Gitea and Caddy using Docker Compose. Caddy handles TLS automatically via Let's Encrypt.

Prerequisites

  • Docker and Docker Compose installed (from 01-arch-install.md)
  • git.example.com resolving to your home IP (from 05-ddns.md)
  • Router port forwards: 80, 443, 2222 pointing to server

1. Router port forwards

Adapt if yours differs: menu names below are from one TP-Link model.

On the router's admin page, Advanced → NAT Forwarding → Virtual Servers → Add, once per row:

Service Type External port Internal IP Internal port Protocol
http 80 192.168.1.50 80 TCP
https 443 192.168.1.50 443 TCP
gitea-ssh 2222 192.168.1.50 2222 TCP

Use Virtual Servers, not Port Triggering.

Port 80 must be forwarded even though Gitea is HTTPS-only — Let's Encrypt's HTTP-01 challenge answers on it, and Caddy cannot issue a certificate without it. Caddy redirects real traffic to 443 itself.

If 443 refuses to save, the router's own Remote Management is holding it — disable it (Advanced → System Tools → Administration), see 02-server-first-boot.md step 4.

Confirm the host firewall from 08-firewall.md is loaded before adding these. Forwarding into a box with no ruleset exposes every listening service on it.

2. Project directory

Clone or copy the project to the server. All runtime data lives in subdirectories next to compose.yml:

cd /home/admin/mithlond   # or wherever you placed the project

# create runtime directories (gitignored)
mkdir -p gitea-data caddy-data caddy-config

# shared network with an optional apex-site stack — declared external in both compose files,
# so it must exist before either stack starts
docker network create edge

compose.yml declares edge as external: true. Without this command docker compose up fails outright with network edge declared as external, but could not be found — it will not create it for you.

3. Verify compose.yml

compose.yml already has the real hostname (git.example.com). Confirm it looks right:

grep DOMAIN compose.yml

4. Verify Caddyfile

Caddyfile ships with placeholder hostnames (example.com) and Let's Encrypt email (you@example.com). Replace them:

grep -nE 'example.com|you@' Caddyfile   # replace each with your own values

Three site blocks: git. → gitea, the apex → portfolio:8000 (optional), and www. → permanent redirect to the apex. Caddy requests a certificate for every name it is configured to serve, so all three must resolve publicly before the production run in step 6, or ACME fails on the ones that do not and burns rate limit. The apex block proxies to a container in the edge network that is deployed separately; until that site is up the block answers 502 (or delete it and the www. block if you host only Gitea), which is expected and does not affect git..

5. Test with Let's Encrypt staging

Before going live, test with the staging CA to avoid hitting rate limits (5 failed issuances per domain per hour).

In the global options block at the top of Caddyfile, uncomment the acme_ca line:

{
    email you@example.com
    acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}

Start the stack:

docker compose up -d

Watch logs for cert issuance:

docker compose logs -f caddy

Look for: certificate obtained successfully. Staging certs are NOT trusted by browsers — that is expected.

Check Gitea is reachable internally:

curl -s http://localhost:3000
# should return HTML

6. Switch to production Let's Encrypt

Re-comment the acme_ca line in the global options block (leave email in place).

# Remove caddy-data to clear staging cert
docker compose down
rm -rf caddy-data
mkdir caddy-data
docker compose up -d

Watch logs again:

docker compose logs -f caddy
# look for: certificate obtained successfully

Visit https://git.example.com in a browser — should load with a valid (trusted) certificate.

7. Enable compose autostart on boot

sudo systemctl enable docker

Docker Compose services with restart: unless-stopped start automatically when Docker starts.

To make the stack start on boot without manual docker compose up:

Create /etc/systemd/system/mithlond.service:

[Unit]
Description=Mithlond Docker Compose stack
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/admin/mithlond
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
User=admin

[Install]
WantedBy=multi-user.target

Enable it:

sudo systemctl enable mithlond

Checklist

  • docker network create edge run on the host
  • Router forwards 80, 443, 2222 to server (only after 09)
  • Staging cert issued successfully in Caddy logs
  • Production cert issued — browser shows valid TLS
  • https://git.example.com loads Gitea
  • mithlond.service enabled — stack survives reboot

Next step

Continue with 07-gitea-setup.md.