← Back to Cyber ← Volver a Cyber

Cyber · Homelab

Building a Self-Hosted Home Server with Docker, a Cloudflare Tunnel and Tailscale Un servidor casero autoalojado con Docker, Cloudflare Tunnel y Tailscale

Este artículo solo está disponible en inglés.

A hands-on account of what worked, what broke, and why. Domain names, passwords, keys, and IP addresses have been generalized.

Overview

I started the day with a freshly installed Docker and a wish list: Jellyfin for movies, Navidrome for music, Kavita for books, Audiobookshelf for audiobooks, Immich for photos, Papra for scanned documents, plus Portainer and Nginx Proxy Manager to manage it all. I ended the day with everything running on a spare EliteDesk, reachable from anywhere, with a private VPN for the sensitive parts, a music downloader, and a watchdog that messages me on Signal when something breaks.

Nothing went smoothly, and the errors turned out to be the most useful part. The biggest one was port forwarding, the textbook way to expose a home server. It failed completely, because my server sits behind two routers and the outer one isn’t mine to change. I threw it out and used a Cloudflare Tunnel for public access and Tailscale for private access.

What it does

A container is one app running in its own sealed box with everything it needs. Docker Compose lets me describe all the boxes in one text file and start them with one command. Reaching them from outside the house then follows this path:

  1. A visitor types a name like jellyfin.yourdomain.com.
  2. DNS translates the name into a Cloudflare address.
  3. Cloudflare passes the request down a tunnel that my server opened outward, so nothing has to be forwarded on the router.
  4. A small program on the server (cloudflared) hands the request to the right container by name.
  5. Private apps (admin panels, the music downloader, the monitor) skip all of this and are reachable only over Tailscale.

Benefits:

Hardware and software

AppWhat it doesPortReached through
JellyfinMovies and video8096Tunnel
NavidromeMusic streaming4533Tunnel
KavitaBooks and comics5000Tunnel
AudiobookshelfAudiobooks and podcasts13378Tunnel
PapraScanned documents1221Tunnel
ImmichPhoto backup2283Tunnel and Tailscale
Soulbeet + slskdMusic finder and downloader9765, 5030Tailscale only
PortainerContainer control panel9443Home network and Tailscale only
Nginx Proxy ManagerReverse proxy (used in Plan A)80, 443, 81Home network
Uptime KumaMonitoring and alerts3001Tailscale only

Part 1: Docker and the Compose file

How Docker Compose works

Step 1: Confirm Docker works

Open Docker Desktop, accept the terms, let it install or update WSL 2, and wait for the green “Engine running” label. Then in PowerShell:

docker --version
docker compose version

Step 2: Write the compose file

One docker-compose.yml defined all seven original apps. Here is the pattern, using Jellyfin:

name: homelab

networks:
  proxy:
    name: proxy

volumes:
  jellyfin_config:
  # ...one named volume per app

services:
  jellyfin:
    image: jellyfin/jellyfin:latest
    container_name: jellyfin
    restart: unless-stopped
    environment:
      - TZ=${TZ}
    ports:
      - "8096:8096"
    volumes:
      - jellyfin_config:/config
      - ${MOVIES_PATH}:/media/movies:ro
      - ${MUSIC_PATH}:/media/music:ro
    networks: [proxy]

The values in ${...} come from a separate .env file:

TZ=America/Los_Angeles
MOVIES_PATH=C:/Media/Movies
MUSIC_PATH=C:/Media/Music
BOOKS_PATH=C:/Media/Books
AUDIOBOOKS_PATH=C:/Media/Audiobooks
PAPRA_AUTH_SECRET=<a long random string>
LineWhat it does
image:Which app to download
container_name:The name used in commands and logs
restart: unless-stoppedRestarts after a crash or a reboot
"8096:8096"host_port:container_port. The left number is the door on the PC, the right one is inside the container
jellyfin_config:/configA named volume for settings and databases
${MOVIES_PATH}:/media/movies:roA bind mount of my movie folder. ro means read-only
networks: [proxy]Joins the shared network

Use forward slashes in Windows paths here. Backslashes are special characters in these files.

Decisions I’m glad I made:

Step 3: Start everything

cd C:\homelab
docker compose up -d
docker ps

-d (detached) runs it in the background. docker ps lists running containers; every row should say Up.

Mistake #1: “I don’t have Jellyfin or any of the other apps”

I expected installers and Start-menu icons. Docker doesn’t work that way. The apps exist as images and containers, visible in Docker Desktop under Containers, and the command that “installs” all of them is docker compose up -d.

Mistake #2: The missing .env file

The first launch printed this:

WARN[0000] The "TZ" variable is not set. Defaulting to a blank string.
WARN[0000] The "MUSIC_PATH" variable is not set. Defaulting to a blank string.
invalid spec: :/audiobooks: empty section between colons

With no .env, ${AUDIOBOOKS_PATH} was blank, so the line became :/audiobooks, which is nonsense. Files that start with a dot often get renamed during download (env, or .env.txt). Fix: create the file by hand and check its exact name with dir -Force, which also lists hidden and dot-files.

Mistake #3: Portainer “timed out”

Portainer makes you create the admin account within a few minutes of first start; otherwise a stranger who reaches the page first could claim the control panel. Fix: docker restart portainer and be quick. Newer versions also print a one-time setup token in docker logs portainer.

Mistake #4: Papra refused to start

docker logs papra showed:

auth.secret (AUTH_SECRET): Invalid length: Expected >=32 but received 16

Fix: generate a long random secret in PowerShell, paste it into .env, and rebuild only that container:

-join ((48..57)+(65..90)+(97..122) | Get-Random -Count 48 | % {[char]$_})
docker compose up -d --force-recreate papra

48..57 are the character codes for digits, 65..90 for capital letters, and 97..122 for lowercase. A plain docker restart would not pick up changed settings, which is why --force-recreate is needed.

Mistake #5: Papra “Invalid application origin”

Papra compares the address in the browser with its APP_BASE_URL setting, as protection against forged requests. I had set it to the future public address while testing at http://localhost:1221. Fix: match it to whatever address I’m actually using, and recreate the container.

When an app asks for a library folder on first run, type the path inside the container, not the Windows path: Jellyfin movies are /media/movies, Kavita is /books, and Audiobookshelf is /audiobooks.

Part 2: Plan A, port forwarding (why it failed)

How port forwarding works

Every device at home shares one public address, and the router sorts the traffic (NAT). A connection started from inside is easy: the router remembers who asked. A connection started from the internet has nowhere to go unless I add a rule: “traffic arriving on port 443 goes to this device.” That rule is port forwarding. The standard recipe is to buy a domain, point it at the home IP, run a reverse proxy, and forward ports 80 and 443 to it.

I did the groundwork: a DHCP reservation for the server, a wildcard * CNAME in Cloudflare set to DNS-only, a dynamic-DNS script on a Raspberry Pi, and a wildcard Let’s Encrypt certificate in Nginx Proxy Manager using the DNS challenge with a Cloudflare API token scoped to one zone. (The HTTP challenge needs open ports, which I didn’t have, and wildcards can only use the DNS challenge anyway.)

Mistake #6: Planning the network before looking at it

The router admin page was a GL.iNet panel. I was about to forward 80 and 443 to the server when it came out that this was a travel router plugged into the family’s ISP router, not the internet.

Internet
   | (one public IP, owned by the ISP router)
+--v-------------------+
| Family router        |  <- not mine, "please don't touch"
| (ISP-provided)       |
+--+-------------------+
   |
+--v-------------------+
| Travel router        |  <- mine; rules here forward traffic that never arrives
| (GL.iNet)            |
+--+-------------------+
   |
+--v-------------------+
| EliteDesk + Docker   |
+----------------------+

This is double NAT. A rule on the inner router only works if the outer router first sends the traffic to it, so the outer router needs matching rules too. The obstacles:

  1. Double NAT. Forwarding on my router alone does nothing.
  2. Not my router. My parents didn’t want their network touched, and that’s fair.
  3. Password wall. The admin password had been changed, and resetting the router would wipe the whole house’s Wi-Fi.
  4. Provider quirks. Some ISP gateways push port forwarding into an app for the account holder and may block inbound port 80.
  5. CGNAT risk. If the router’s WAN address starts with 100. or a private range, another NAT sits upstream and forwarding can’t work at all.

Lesson: check how the network is actually connected before designing around it. One look at the router’s WAN page would have shown the double NAT within a minute.

OptionVerdict
Ask my parents to forward port 443 to my travel routerWorks, but needs their permission and their router
Cloudflare TunnelWorks behind any router, nothing to forward
TailscaleWorks behind any router, but only for devices I install it on

Decision: Cloudflare Tunnel for public access and Tailscale for private access.

Part 3: Plan B, the Cloudflare Tunnel

How a tunnel works

Instead of asking the front door to let visitors in, the server digs a passage out to Cloudflare. Visitors knock on Cloudflare’s door, and Cloudflare walks them through the passage. Nobody ever knocks on the house.

Technically, cloudflared runs next to the apps and opens outbound, encrypted connections to Cloudflare. That avoids every problem from Part 2:

Step 1: Create the tunnel

In the Cloudflare dashboard: Networking → Tunnels → Create Tunnel → Cloudflared, name it homelab, choose Docker, and copy the token from the command it shows. The token is one very long string that starts with eyJ.

Mistake #7: Tunnel ID instead of tunnel token

The container kept printing Provided Tunnel token is not valid. I had copied the tunnel ID, a short code with dashes, instead of the token. The ID only names the tunnel; the token is the password the container uses to log in.

Lesson: when a credential is rejected, check that it’s the right kind of credential before assuming it’s mistyped.

Step 2: Add it to the stack

Add CLOUDFLARE_TUNNEL_TOKEN=eyJ... to .env, then add this service to docker-compose.yml:

  cloudflared:
    image: cloudflare/cloudflared:latest
    container_name: cloudflared
    restart: unless-stopped
    command: tunnel --no-autoupdate run
    environment:
      - TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN}
    networks: [proxy]
docker compose up -d
docker logs cloudflared --tail 20

The logs should say the tunnel connection registered, and the dashboard flips to Healthy.

Step 3: Tell Cloudflare where each name goes

Inside the tunnel’s page: Routes → Add route → Published application.

SubdomainService URL
jellyfinhttp://jellyfin:8096
bookshttp://kavita:5000
audiobookshttp://audiobookshelf:80
musichttp://navidrome:4533
papershttp://papra:1221

Note audiobookshelf:80, not 13378. The tunnel talks to the container directly, so it uses the port inside the container. 13378 is only the door on the PC.

Mistake #8: The wrong Routes page

The dashboard’s left menu has an account-wide Routes page for private networks (CIDR ranges). That isn’t where published applications live. The routes I needed are inside the tunnel’s own page.

Test: turn off Wi-Fi on a phone, use cellular, and open https://papers.yourdomain.com. Login page, padlock, done.

Step 4: Clean up

I deleted two DNS records: the home A record, which was publishing my parents’ public IP address for anyone to look up, and the * wildcard CNAME. I also switched off the dynamic-DNS cron job on the Raspberry Pi (crontab -e) so it couldn’t recreate the IP record.

Mistake #9: Underestimating the free-plan limits

I first described tunneling video as a “gray area.” After reading Cloudflare’s own documentation, that was too soft. On the free plans, serving video and other large files through Cloudflare’s network requires a specific paid service, and tunneling Jellyfin can break those terms. The risk is a throttled or suspended account, and my domain lives there. Free plans also cap uploads at 100 MB per request, which breaks large video uploads to Immich.

Lesson: read the fine print of free tiers when the account holds something you care about. My plan: the public tunnel for light apps, and Tailscale for heavy streaming and big backups.

Part 4: Tailscale, the private network

How Tailscale works

Tailscale builds a private network for my own devices. Each one gets an address starting with 100., and they can reach each other as if they were on one home network, from anywhere. Underneath it’s an encrypted WireGuard mesh. Devices connect outward to Tailscale’s coordination service, so no port forwarding is needed and it works behind my double NAT.

Anything not on the tunnel stays reachable only through it: Portainer, Nginx Proxy Manager, Soulbeet, slskd, and Uptime Kuma.

Step 1: Install and test

Install Tailscale on the server and the phone, sign in with the same account, and each device appears in the admin console with its own 100.x.x.x address. From the phone with Wi-Fi off, apps load at addresses like http://100.x.x.x:8096. Plain http:// is fine here, because Tailscale already encrypts everything.

Mistake #10: Two separate tailnets

The admin page showed one machine, the phone. The server had signed in to a different account, probably because the browser auto-picked another saved account. Two accounts means two separate networks that can’t see each other.

The reliable fix is an auth key (Settings → Keys → Generate auth key, 1 day, not reusable):

tailscale logout
tailscale up --auth-key=tskey-auth-XXXXXXXX

An auth key is a one-day guest pass. The server presents it and joins the right network directly, with no browser and no account picker.

Lesson: when two devices can’t see each other, compare the account on each one before touching anything else.

Mistake #11: “tailscale is not recognized”

PowerShell didn’t know where the program lived in that session. The fix is to call it by its full path with the & call operator:

Test-Path "C:\Program Files\Tailscale\tailscale.exe"
& "C:\Program Files\Tailscale\tailscale.exe" up --auth-key=tskey-auth-XXXXXXXX

To keep the server on the network: enable Run unattended so it connects after a reboot before anyone signs in, and disable key expiry for the server in the admin console.

Part 5: Immich (photos)

Immich is four containers working as a team (server, machine learning, a Redis-compatible cache, and a Postgres database), and it changes often. So it got its own folder and its own compose file, using the official files from Immich’s GitHub releases instead of a recipe that goes stale.

cd C:\immich
ren example.env .env

In .env, set UPLOAD_LOCATION=C:/immich/library, DB_DATA_LOCATION=pgdata, the time zone, and a random DB_PASSWORD (letters and numbers only). pgdata puts the database in a Docker named volume, because Postgres on a Windows-mounted folder can run into permission and speed problems.

Mistake #12: A YAML error

go-yaml load error in scanner (while scanning a simple key) at L79.C3-L80.C1:
could not find expected ':'

YAML is strict: every key needs a colon, and indentation carries meaning. The new pgdata line was indented differently from the lines around it. The end of the file needed to look exactly like this, with spaces and no tabs:

volumes:
  model-cache:
  pgdata:

Lesson: always validate before starting. This prints nothing if the file is valid and an error with a line number if not:

docker compose config --quiet

Mistake #13: Misreading the naming request

I wanted immich.yourdomain.com handled like the other apps, through the tunnel. Immich lives in its own compose project and network, so the tunnel can’t find it by container name. The route is http://host.docker.internal:2283, a special name from Docker Desktop that means “the PC itself,” where port 2283 is published. Because of the 100 MB upload cap, big video backups go over the Tailscale address instead.

Part 6: Soulbeet and slskd (music downloader)

Only download music you have the right to have. Both apps stay off the tunnel and are reachable only over Tailscale.

Finding the right folders

docker ps and Portainer’s container details showed Navidrome’s music mount, and the com.docker.compose.project.working_dir label pointed at the compose folder. Then I confirmed the music variable:

Get-Content C:\HOMELAB\.env | Where-Object { $_ -match '^MUSIC_PATH=' }

Before editing, a health check and a backup:

docker compose -f C:\HOMELAB\docker-compose.yml config --quiet
Copy-Item C:\HOMELAB\docker-compose.yml C:\HOMELAB\docker-compose.backup.yml

Mistake #14: Typing a path as if it were a command

PowerShell answered C:\Media\Downloads : The term ... is not recognized. A path by itself isn’t a command. Nothing broke.

Mistake #15: An empty secret key

The first attempt at generating Soulbeet’s secret key called Python, which isn’t installed. PowerShell printed “Python was not found” but kept going and wrote an empty SECRET_KEY= line into .env.

Lesson: a failed command can still leave a half-finished change behind. Check what a command actually wrote, instead of trusting the “success” message that follows it.

Mistake #16: A method that doesn’t exist in Windows PowerShell

A .NET shortcut failed because Windows PowerShell 5.1 runs on an older .NET. The version that works there asks the operating system for 32 cryptographically random bytes:

$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$bytes = New-Object byte[] 32
$rng.GetBytes($bytes)
$key = [Convert]::ToBase64String($bytes)
$rng.Dispose()

Adding both services

  slskd:
    image: slskd/slskd:latest
    container_name: slskd
    restart: unless-stopped
    ports:
      - "5030:5030"
    environment:
      - SLSKD_REMOTE_CONFIGURATION=true
    volumes:
      - ./slskd/data:/app
      - C:/Media/Downloads:/app/downloads
    networks: [proxy]

  soulbeet:
    image: docker.io/docccccc/soulbeet:latest
    container_name: soulbeet
    restart: unless-stopped
    ports:
      - "9765:9765"
    environment:
      - DATABASE_URL=sqlite:/data/soulbeet.db
      - SLSKD_URL=http://slskd:5030
      - SLSKD_API_KEY=${SLSKD_API_KEY}
      - SLSKD_DOWNLOAD_PATH=/downloads
      - SECRET_KEY=${SECRET_KEY}
      - NAVIDROME_URL=http://navidrome:4533
    volumes:
      - ./soulbeet/data:/data
      - C:/Media/Downloads:/downloads
      - ${MUSIC_PATH}:/music
    depends_on:
      - navidrome
      - slskd
    networks: [proxy]

Navidrome keeps /music read-only, while Soulbeet gets write access to the same folder so beets can file new music.

Mistake #17: Placeholder text left in the config

slskd’s API key is configured in its own YAML (System → Options). The template I pasted still held placeholder words like CHOOSE-A-USERNAME. Saved as-is, slskd would have logged in to Soulseek with that literal name. I caught it before saving.

Lesson: reread any pasted template for leftover placeholders before saving it.

Mistake #18: curl.exe wasn’t available

The built-in PowerShell version works everywhere, and reading the key from .env means it never gets typed or pasted:

$k = ((Get-Content C:\HOMELAB\.env | Where-Object { $_ -match '^SLSKD_API_KEY=' }) -replace '^SLSKD_API_KEY=','').Trim()
$r = Invoke-RestMethod -Headers @{"X-API-Key"=$k} http://100.x.x.x:5030/api/v0/application
$r.server.state

The answer Connected, LoggedIn ruled out slskd, so the problem had to be on the Soulbeet side.

Mistake #19: Looking inside a container that has no tools

docker exec soulbeet env failed with executable file not found; the image is stripped down. Ask Docker from the outside instead:

docker inspect soulbeet --format '{{range .Config.Env}}{{println .}}{{end}}' | findstr SLSKD

It showed the slskd address and key, so the container had them. That key was printed on screen and later pasted into a chat, so I’m rotating it.

Mistake #20: The Config page that only mentioned Navidrome

I was logged in as a normal user. This Soulbeet version splits admin and user accounts, and the slskd and folder settings are admin-only. Fix: log in as the built-in admin, change that password immediately, and fill in the slskd URL, API key, and download path.

Lesson: when a settings page looks incomplete, check which account you’re on before assuming the feature is missing.

Mistakes #21–23: Wrong tests and wrong docs

Part 7: Uptime Kuma (monitoring)

Uptime Kuma checks every service once a minute and alerts me when one stops answering. It got its own folder, so the big compose file stayed untouched:

services:
  uptime-kuma:
    image: louislam/uptime-kuma:2
    container_name: uptime-kuma
    restart: unless-stopped
    ports:
      - "3001:3001"
    volumes:
      - kuma_data:/app/data

volumes:
  kuma_data:

I chose SQLite (one file, no setup). Monitors: HTTP(s) every 60 seconds for each public address, which tests the whole path (DNS, Cloudflare, the tunnel, and the container), plus TCP port monitors against host.docker.internal for the private apps. Alerts go to Signal.

One limit: Uptime Kuma lives on the same PC. If the whole machine or the internet goes down, the watchdog goes down with it. A free outside monitor covers that gap.

Error cheat sheet

SymptomLayerWhat it meansFix
variable is not set, :/audiobooksConfiguration.env wasn’t readCreate .env, check the exact name with dir -Force
Container exits with a config errorApplicationA setting is invaliddocker logs NAME, fix it, --force-recreate
”Invalid application origin”ApplicationBrowser address doesn’t match the app’s settingMatch APP_BASE_URL to the address used
Port forward does nothingNetworkDouble NAT or CGNAT upstreamUse a tunnel or Tailscale
”Tunnel token is not valid”AuthenticationTunnel ID pasted instead of the tokenCopy the eyJ... token
Cloudflare 502 on a routeApplicationWrong container name or port in the routeFix the Service URL
Tailscale shows one deviceAccountDevices signed in to different accountsUse an auth key
tailscale not recognizedShellProgram not on that session’s pathRun it by full path with &
YAML “could not find expected ’:‘“SyntaxBad indentation or a missing colonFix the line, run config --quiet
slskd returns 401AuthenticationAPI keys don’t matchUse the same key in slskd and the client
exec: "env": not foundToolingMinimal image has no shell toolsUse docker inspect --format
Settings page missing optionsAuthorizationLogged in as a normal userLog in as admin

Hardening and reliability checklist

These are recommendations, not all finished work:

Takeaways

  1. Check the network before designing around it. One look at the router’s WAN page would have revealed the double NAT and saved an hour.
  2. Outbound beats inbound. Tunnels and VPN meshes connect outward, so they work where port forwarding can’t.
  3. Validate before launching. docker compose config --quiet and a glance at docker logs turn mysteries into one-line errors.
  4. Silent failures are the worst kind. The empty SECRET_KEY looked fine until it wasn’t.
  5. Read the error, not just the message. A 401 versus a 502 versus “not valid” each pointed at a different layer: credentials, routing, or the wrong kind of credential.
  6. Know which account you’re on. Two Tailscale accounts and an admin-versus-user Soulbeet account produced the same symptom: settings that seemed to be missing.
  7. Don’t paste secrets. Keys went into a chat and a screenshot. Rotate them.
  8. Read the fine print. Free-tier terms matter when the domain you care about lives there.

← Back to Cyber ← Volver a Cyber