← How-Tos
raspberry-pi May 7, 2026 ◯ 8 min read

Raspberry Pi Home Server Guide: Self-Hosting, Docker, and Home Automation

Why Build a Raspberry Pi Home Server?

A Raspberry Pi home server is a low-power, always-on computer that runs services on your local network: file storage, media streaming, home automation, ad blocking, VPN, code repositories, and more. At 5-15W power draw, it costs under $15/year in electricity compared to $200+ for a full PC running 24/7. This guide covers building a robust Pi server from scratch with Docker containerization.

Hardware Selection and Setup

Choosing the Right Pi

ModelRAMBest ForPrice Pi 4B (4GB)4GB LPDDR4Light home server, Pi-hole, Home Assistant, small NAS$55 Pi 4B (8GB)8GB LPDDR4Multi-service Docker host, media server, moderate databases$75 Pi 5 (8GB)8GB LPDDR4XHeavy workloads, 4K transcoding, multiple VMs, fast NAS$80 Pi 5 (16GB)16GB LPDDR4XPower user setup, large databases, development server$120

Recommendation: The Pi 4B 8GB offers the best price/performance for most home servers. The Pi 5 is worth the upgrade if you need USB 3.0 storage performance or plan to run many containers.

Required Accessories

Operating System Installation

Option 1: Raspberry Pi OS Lite (64-bit)

The official OS. Best compatibility, smallest footprint.

  1. Download Raspberry Pi Imager from raspberrypi.com/software.
  2. Select Raspberry Pi OS Lite (64-bit) — no desktop environment needed for a headless server.
  3. Click the gear icon (Settings) before flashing:
    • Enable SSH (required for headless access)
    • Set username and password (don't use default pi/raspberry)
    • Configure WiFi (temporary, you'll switch to wired later)
    • Set locale and timezone
  4. Flash to your SD card or SSD.
  5. Insert storage, connect Ethernet, power on. Wait 2 minutes for first boot.
  6. Find the IP address via your router's admin panel or ping raspberrypi.local.
  7. SSH in: ssh [email protected]

Option 2: Ubuntu Server LTS

Better for advanced users who want standard Linux tooling and long-term support.

  1. In Raspberry Pi Imager, choose Ubuntu Server 24.04 LTS (64-bit).
  2. Flash, boot, and SSH in (default user: ubuntu, password: ubuntu — forced change on first login).
  3. Ubuntu uses netplan for networking and snap for package management.

Initial System Hardening

Before installing any services, secure your server:

  1. Update everything: sudo apt update && sudo apt full-upgrade -y
  2. Create a non-root user (if not done during imaging): sudo adduser yourname sudo usermod -aG sudo yourname
  3. Configure SSH hardening: sudo nano /etc/ssh/sshd_config Set these values: PermitRootLogin no PasswordAuthentication no # after setting up keys MaxAuthTries 3 ClientAliveInterval 300 ClientAliveCountMax 2
  4. Set up SSH key authentication: ssh-copy-id [email protected] Then disable password auth in sshd_config and restart SSH: sudo systemctl restart sshd
  5. Install fail2ban: sudo apt install fail2ban -y sudo systemctl enable fail2ban This automatically bans IP addresses after 5 failed SSH login attempts.
  6. Configure automatic security updates: sudo apt install unattended-upgrades -y sudo dpkg-reconfigure unattended-upgrades # select Yes
  7. Set up a firewall (UFW): sudo apt install ufw -y sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable
  8. Set a static IP address: Edit /etc/dhcpcd.conf (Pi OS) or netplan config (Ubuntu): interface eth0 static ip_address=192.168.1.10/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 1.1.1.1

Storage Setup: External Drives and NAS

Mounting USB Storage

  1. Connect your USB SSD or HDD. Find its device name: lsblk (look for sda, sdb, etc.)
  2. Format if new (WARNING: erases all data): sudo mkfs.ext4 /dev/sda1
  3. Create mount point: sudo mkdir /mnt/data
  4. Get the UUID: sudo blkid /dev/sda1
  5. Add to /etc/fstab for automatic mounting: UUID=your-uuid-here /mnt/data ext4 defaults,noatime 0 2
  6. Mount: sudo mount -a
  7. Set ownership: sudo chown -R $USER:$USER /mnt/data

Network Share (Samba NAS)

sudo apt install samba -y Edit /etc/samba/smb.conf and add: [share] path = /mnt/data valid users = @users force group = users read only = no writable = yes create mask = 0664 directory mask = 0775 browsable = yes sudo smbpasswd -a $USER sudo systemctl restart smbd Access from Windows: \192.168.1.10\share | From Mac: Finder → Go → Connect to Server → smb://192.168.1.10/share

Docker Installation and Setup

Docker is the standard for self-hosting. It isolates applications, makes updates trivial, and keeps your host OS clean.

  1. Install Docker: curl -fsSL https://get.docker.com | sh
  2. Add your user to the docker group: sudo usermod -aG docker $USER newgrp docker
  3. Install Docker Compose: (included with modern Docker as docker compose)
  4. Create a directory structure: mkdir -p ~/docker/{compose,data,configs} cd ~/docker/compose

Essential Self-Hosted Services

1. Pi-hole (Network-Wide Ad Blocking)

Blocks ads and trackers at the DNS level for every device on your network.

mkdir ~/docker/compose/pihole && cd ~/docker/compose/pihole

Create docker-compose.yml:

services: pihole: image: pihole/pihole:latest container_name: pihole ports: - "53:53/tcp" - "53:53/udp" - "8081:80/tcp" environment: - TZ=America/New_York - WEBPASSWORD=your_admin_password volumes: - ~/docker/data/pihole/etc-pihole:/etc/pihole - ~/docker/data/pihole/etc-dnsmasq.d:/etc/dnsmasq.d restart: unless-stopped

Then: docker compose up -d

Router setup: Set your router's DNS server to your Pi's IP (192.168.1.10). Now every device on your network gets ad blocking automatically. Access the admin panel at http://192.168.1.10:8081/admin.

2. Home Assistant (Home Automation)

The gold standard for local home automation. Supports thousands of devices.

mkdir ~/docker/compose/homeassistant && cd ~/docker/compose/homeassistant services: homeassistant: image: homeassistant/home-assistant:stable container_name: homeassistant privileged: true network_mode: host environment: - TZ=America/New_York volumes: - ~/docker/data/homeassistant:/config - /run/dbus:/run/dbus:ro restart: unless-stopped

Access at http://192.168.1.10:8123. On first boot, create an account and it will auto-discover many devices on your network.

3. Jellyfin (Media Server)

Open-source Plex alternative. Stream your movies, TV shows, and music to any device.

services: jellyfin: image: jellyfin/jellyfin:latest container_name: jellyfin network_mode: host volumes: - ~/docker/data/jellyfin/config:/config - ~/docker/data/jellyfin/cache:/cache - /mnt/data/media:/media:ro restart: unless-stopped

Place media in /mnt/data/media/movies and /mnt/data/media/tvshows. Jellyfin will scan and organize them automatically.

4. Nextcloud (Personal Cloud Storage)

Self-hosted Dropbox/Google Drive alternative. File sync, sharing, calendar, contacts, and office editing.

services: nextcloud: image: nextcloud:latest container_name: nextcloud ports: - "8082:80" volumes: - ~/docker/data/nextcloud/html:/var/www/html - /mnt/data/nextcloud:/var/www/html/data environment: - MYSQL_PASSWORD=nextcloud_db_pass - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud - MYSQL_HOST=nextcloud-db restart: unless-stopped nextcloud-db: image: mariadb:10.6 container_name: nextcloud-db volumes: - ~/docker/data/nextcloud/db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=root_db_pass - MYSQL_PASSWORD=nextcloud_db_pass - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud restart: unless-stopped

5. WireGuard VPN (Remote Access)

Access your home network securely from anywhere.

services: wireguard: image: linuxserver/wireguard:latest container_name: wireguard cap_add: - NET_ADMIN - SYS_MODULE environment: - PUID=1000 - PGID=1000 - SERVERURL=your-domain.duckdns.org - SERVERPORT=51820 - PEERS=phone,laptop,tablet volumes: - ~/docker/data/wireguard:/config ports: - "51820:51820/udp" sysctls: - net.ipv4.conf.all.src_valid_mark=1 restart: unless-stopped

After starting, client configs are generated in ~/docker/data/wireguard/peer_phone/ etc. Scan the QR code with the WireGuard mobile app.

6. Portainer (Docker Management GUI)

Web UI for managing Docker containers, images, volumes, and networks.

services: portainer: image: portainer/portainer-ce:latest container_name: portainer ports: - "9000:9000" volumes: - /var/run/docker.sock:/var/run/docker.sock - ~/docker/data/portainer:/data restart: unless-stopped

Access at http://192.168.1.10:9000. Create an admin account on first login.

Backup Strategy

Your Pi server becomes the backbone of your digital life — back it up properly:

  1. SD card/SSD image backup (weekly): sudo dd if=/dev/mmcblk0 of=/mnt/data/backups/pi-backup-$(date +%Y%m%d).img bs=4M status=progress (Replace /dev/mmcblk0 with your actual boot device — check with lsblk)
  2. Docker volume backup (daily): #!/bin/bash BACKUP_DIR=/mnt/data/backups/docker tar czf $BACKUP_DIR/docker-data-$(date +%Y%m%d).tar.gz ~/docker/data
  3. Offsite sync with rclone: sudo apt install rclone -y rclone config # set up Google Drive, Dropbox, S3, etc. rclone sync /mnt/data/backups remote:pi-backups
  4. Automate with cron: crontab -e # Add lines: 0 2 * * 0 /home/yourname/scripts/backup-image.sh # Weekly image backup 0 3 * * * /home/yourname/scripts/backup-docker.sh # Daily Docker backup 0 4 * * * rclone sync /mnt/data/backups gdrive:pi-backups

Performance Monitoring

Keep an eye on your Pi's resources:

Power Optimization

Reduce power consumption and heat generation:

Troubleshooting

ProblemSolution Undervoltage warnings (yellow lightning bolt)Use official power supply; check cable quality; reduce USB peripheral load SD card corruptionSwitch to SSD; enable logging to RAM (log2ram); avoid abrupt power cuts Docker containers won't startCheck port conflicts; verify volume permissions; read logs: docker compose logs Slow network speedsUse Ethernet not WiFi; check cable quality; verify USB 3.0 port (blue) for SSD Running out of RAMAdd swap file: sudo dphys-swapfile setup; or upgrade to 8GB Pi; limit container memory Services not accessible from other devicesCheck UFW rules; verify network_mode: host vs bridge; check router firewall