DEV Community

selfhosting.sh
selfhosting.sh

Posted on • Originally published at selfhosting.sh

How to Self-Host a Valheim Server with Docker

Why Self-Host a Valheim Server?

A self-hosted Valheim server runs 24/7, so your friends can play even when you are offline. Unlike renting from a game server provider, you control world settings, mods, and backups — and you pay nothing beyond the hardware cost. The lloesche/valheim-server Docker image handles SteamCMD, automatic updates, scheduled restarts, and hourly backups out of the box.

Official project: lloesche/valheim-server-docker on GitHub

Prerequisites

  • A Linux server (Ubuntu 22.04+ recommended) with Docker and Docker Compose installed
  • 4 GB of RAM minimum (8 GB recommended)
  • 2+ CPU cores — clock speed matters more than core count for Valheim
  • 5 GB of free disk space (plus world save growth over time)
  • UDP ports 2456-2457 open on your firewall or router (port forwarding guide)

Docker Compose Configuration

services:
  valheim:
    image: ghcr.io/lloesche/valheim-server
    container_name: valheim-server
    cap_add:
      - sys_nice
    ports:
      - "2456-2457:2456-2457/udp"
    environment:
      SERVER_NAME: "My Valheim Server"
      SERVER_PASS: "atleast5chars"
      WORLD_NAME: "MyWorld"
      SERVER_PUBLIC: "false"
      TZ: "America/New_York"
      UPDATE_CRON: "*/15 * * * *"
      UPDATE_IF_IDLE: "true"
      RESTART_CRON: "0 5 * * *"
      RESTART_IF_IDLE: "true"
      BACKUPS: "true"
      BACKUPS_CRON: "0 * * * *"
      BACKUPS_ZIP: "true"
      BACKUPS_MAX_AGE: "3"
    volumes:
      - ./valheim-config:/config
      - ./valheim-data:/opt/valheim
    restart: unless-stopped
    stop_grace_period: 120s

Enter fullscreen mode Exit fullscreen mode

Key configuration:

Variable Purpose
SERVER_NAME Name displayed in the server browser
SERVER_PASS Login password — minimum 5 characters, required
WORLD_NAME World name (without file extension). Changing this creates a new world.
SERVER_PUBLIC true lists the server in the browser. false makes it private (join by IP).
cap_add: sys_nice Allows the container to set process priority for better performance
stop_grace_period: 120s Gives the server time to save the world before Docker kills it

Start the server:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

First startup takes 5-10 minutes while SteamCMD downloads Valheim server files (~1 GB). Watch progress with:

docker compose logs -f valheim
Enter fullscreen mode Exit fullscreen mode

The server is ready when you see Game server connected.

Connecting to Your Server

From Valheim:

  1. Click Join GameAdd Server
  2. Enter your-server-ip:2456
  3. Enter the password you set in SERVER_PASS

For LAN play, use the server's local IP. For internet play, forward UDP ports 2456-2457 on your router. Alternatively, use Tailscale for zero-config access without port forwarding.

Automatic Updates and Restarts

The image checks for Valheim updates every 15 minutes by default. When an update is available and no players are online (if UPDATE_IF_IDLE is true), it downloads and installs the update automatically.

Setting Default What It Does
UPDATE_CRON */15 * * * * How often to check for updates
UPDATE_IF_IDLE true Only update when no players are connected
RESTART_CRON 10 5 * * * Daily server restart schedule
RESTART_IF_IDLE true Only restart when no players are connected

To disable automatic updates entirely, set UPDATE_CRON: "".

Backups

Backups are enabled by default. The image creates compressed world backups every hour and cleans up backups older than 3 days.

Setting Default Purpose
BACKUPS true Enable/disable automatic backups
BACKUPS_CRON 5 * * * * Backup schedule (hourly at minute 5)
BACKUPS_ZIP true Compress backups to save disk space
BACKUPS_MAX_AGE 3 Days to keep backups before auto-deletion
BACKUPS_IF_IDLE true Backup even when no players are online

Backups are stored in /config/backups/ inside the container (mapped to ./valheim-config/backups/ on the host).

To restore a backup:

docker compose down
cd valheim-config/backups/
# Unzip the desired backup
unzip backup-YYYYMMDD-HHMMSS.zip -d ../worlds_local/
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

For additional backup strategies, see our backup guide.

Crossplay (Xbox/PC Game Pass)

To allow non-Steam clients (Xbox, PC Game Pass) to connect:

environment:
  SERVER_ARGS: "-crossplay"
Enter fullscreen mode Exit fullscreen mode

Add port 2458 to your port mappings:

ports:
  - "2456-2458:2456-2458/udp"
Enter fullscreen mode Exit fullscreen mode

Crossplay uses PlayFab instead of Steam networking. Both Steam and non-Steam players can connect simultaneously when crossplay is enabled.

Admin Controls

Adding Admins

Set admin SteamID64s via environment variable:

environment:
  ADMINLIST_IDS: "76561198012345678 76561198087654321"
Enter fullscreen mode Exit fullscreen mode

Find your SteamID64 at steamid.io.

Banning Players

environment:
  BANNEDLIST_IDS: "76561198099999999"
Enter fullscreen mode Exit fullscreen mode

Allowlist Mode

Restrict access to specific players only:

environment:
  PERMITTEDLIST_IDS: "76561198012345678 76561198087654321"
Enter fullscreen mode Exit fullscreen mode

When PERMITTEDLIST_IDS is set, only those SteamID64s can join the server.

BepInEx Mods

To enable BepInEx modding framework:

environment:
  BEPINEX: "true"
Enter fullscreen mode Exit fullscreen mode

The BepInEx framework installs automatically on next restart. Place mod DLLs in ./valheim-config/bepinex/plugins/:

cp my-valheim-mod.dll ./valheim-config/bepinex/plugins/
docker compose restart valheim
Enter fullscreen mode Exit fullscreen mode

Note: BepInEx and ValheimPlus are mutually exclusive. BepInEx is the more actively maintained framework and supports most mods on Thunderstore.

Troubleshooting

Server Does Not Appear in Browser

Symptom: SERVER_PUBLIC: "true" but the server is not listed.

Fix:

  • Wait 10-15 minutes after startup — Steam registration can be slow
  • Verify UDP ports 2456-2457 are forwarded and reachable
  • Connect directly by IP (your-ip:2456) instead of using the browser
  • Check docker compose logs valheim for Steam registration errors

Players Get Disconnected Frequently

Symptom: Players kicked with "Disconnected" after a few minutes.

Fix:

  • Ensure SERVER_PASS is at least 5 characters
  • Check server RAM usage — Valheim needs 4+ GB free
  • Verify the host's network is stable (packet loss causes disconnects)
  • If using crossplay, ensure port 2458/udp is also forwarded

World Save Corruption

Symptom: Server starts with a fresh world despite existing saves.

Fix:

  • Check that WORLD_NAME matches exactly (case-sensitive)
  • Verify ./valheim-config/worlds_local/ contains your .db and .fwl files
  • Restore from the latest backup in ./valheim-config/backups/
  • Never use docker compose down -v — this deletes volumes and world data

Resource Requirements

Players RAM CPU Disk
1-3 4 GB 2 cores 5 GB
4-6 6 GB 2-4 cores 10 GB
7-10 8 GB 4 cores 15 GB
10+ 8-12 GB 4 cores (high clock) 20+ GB

Valheim is CPU-bound. A 4-core CPU at 4.0 GHz will perform noticeably better than an 8-core at 2.5 GHz. If you experience tick lag with many players, prioritize clock speed.

Idle server RAM usage is approximately 2.8 GB, with each connected player adding 100-200 MB.

Verdict

The lloesche/valheim-server image is the best way to run a Valheim dedicated server. Built-in automatic updates, scheduled backups, and graceful shutdown handling mean the server mostly runs itself. BepInEx support covers the modding ecosystem. The only downside is that the image uses rolling tags rather than semantic versions — pin to a specific SHA if you need exact reproducibility.

For managing multiple game servers including Valheim, look at Pterodactyl or Crafty Controller.

Related

Top comments (0)