A Valheim dedicated server with Docker gives you a world that stays online when your own PC is off, and it keeps the world files in a Docker volume you can back up. This guide walks through the compose file, the UDP ports Valheim needs, where the world data lives, and how to update the server without wiping anyone's progress.
You will end up with a container that restarts on boot, a world named in the compose file, and a Steam join address your friends can use.
Before you start
You need:
- A Linux VPS with at least a few gigabytes of RAM. Valheim worlds grow as players build, so leave headroom.
- Ubuntu 22.04/24.04, Debian 12, AlmaLinux or Rocky 8–9.
- A non-root user with sudo. The examples use
deploy. - Your server's public IP —
203.0.113.10in the examples. - Docker and Docker Compose installed. If you have not done that yet, follow Install Docker and Docker Compose on a Linux VPS first.
Note: The community image used here is maintained by volunteers, and its environment variable names change occasionally. Check the image's own documentation before you rely on a variable that is not in this guide.
Install Docker and Docker Compose
If Docker is already running, confirm it:
docker --version
docker compose versionIf either command is missing, install Docker from the official repository using the guide linked above, then add your user to the docker group so you do not need sudo for every command:
sudo usermod -aG docker deployLog out and back in for the group change to apply.
Write the Compose file
Create a directory for the stack:
mkdir -p ~/valheim && cd ~/valheimCreate a .env file for the server password so it does not sit in the compose file:
VALHEIM_PASS=change-this-to-a-long-passwordNow create compose.yaml:
services:
valheim:
image: lloesche/valheim-server:latest
container_name: valheim
cap_add:
- sys_nice
stop_grace_period: 2m
ports:
- "2456:2456/udp"
- "2457:2457/udp"
environment:
SERVER_NAME: "My Valheim Server"
WORLD_NAME: "Midgard"
SERVER_PASS: "${VALHEIM_PASS}"
SERVER_PUBLIC: "false"
TZ: "Europe/London"
volumes:
- valheim-config:/config
- valheim-data:/data
restart: unless-stopped
volumes:
valheim-config:
valheim-data:Two things matter here. First, stop_grace_period: 2m gives the server time to write the world to disk when Docker stops the container — without it you risk losing the last few minutes of play. Second, the two named volumes keep your world and configuration outside the container, so pulling a new image never touches them.
Tip: Valheim rejects passwords shorter than five characters, and it also rejects a password that appears inside the server name. Keep them unrelated.
Open the Valheim ports
Valheim uses UDP, not TCP. The game port is 2456 and the Steam query port is 2457. Open both:
sudo ufw allow 2456/udp
sudo ufw allow 2457/udp
sudo ufw statusOn AlmaLinux or Rocky with firewalld:
sudo firewall-cmd --permanent --add-port=2456/udp
sudo firewall-cmd --permanent --add-port=2457/udp
sudo firewall-cmd --reloadWarning: Only open the ports you need. Do not disable the firewall to "test" connectivity — open the two UDP ports and leave the rest closed.
If your provider also has a firewall or security group in front of the VPS, add the same two UDP ports there. A blocked UDP port is the single most common reason a server never appears in the Steam browser.
Start the server and watch the logs
Bring the stack up:
docker compose up -d
docker compose logs -f valheimThe first start downloads the Valheim dedicated server files through SteamCMD, which takes a few minutes. You are waiting for a line that says the game server is listening, followed by the world name. Press Ctrl+C to leave the log view — the container keeps running.
Check the container state:
docker compose psYou want running, not restarting or exited.
Connect from Steam
In Valheim, open the join menu and use Join game with the address:
203.0.113.10:2456The client connects on the game port, not the query port. If you set SERVER_PUBLIC: "false", the server will not be listed publicly — friends join by IP or through the Steam friends list. Set it to "true" if you want it visible in the in-game browser.
Update the Valheim dedicated server safely
Valheim patches break compatibility between client and server versions, so update when your players are offline.
Warning: Stop the server before updating. Pulling a new image while the world is live can interrupt a save and corrupt the current world file.
cd ~/valheim
docker compose stop
docker compose pull
docker compose up -d
docker compose logs -f valheimdocker compose stop sends a graceful shutdown, and the two-minute grace period lets the world save finish. Because the world lives in the valheim-data volume, the new container picks up exactly where the old one left off.
If a new image turns out to be broken, pin the previous tag in compose.yaml and bring the stack back up — the same idea as rolling back a bad deploy using Docker image tags.
Check it works
Confirm the container is listening on UDP:
sudo ss -lunp | grep -E '2456|2457'You should see the Docker proxy bound to both ports. Then:
- Connect from your own Valheim client using
203.0.113.10:2456. - Place a marker or build a small structure, then disconnect.
- Restart the container with
docker compose restartand reconnect. Your build should still be there — that proves the volume is doing its job.
Troubleshooting
- Server never appears in the Steam browser → the query port is blocked or
SERVER_PUBLICis"false". Confirm 2457/udp is open at both the OS and provider firewall, and check the logs for the query port line. - "Password must be at least 5 characters" or the container exits at startup → the password in
.envis too short, or it is contained inSERVER_NAME. Change both and rundocker compose up -dagain. - World resets after an update → the
/datavolume is missing or was recreated. Rundocker volume lsand confirmvalheim-datastill exists; never rundocker compose down -v, which deletes named volumes. - Progress lost after a restart →
stop_grace_periodis too short or missing. Set it to2mand restart the stack. - Clients cannot join after a patch → client and server versions differ. Update the image on the server and update Valheim on every client.
Next steps
- Back up the world volume on a schedule with Back up Docker volumes with restic and restore them.
- Move the server password out of plain text with Manage secrets and environment variables in Docker Compose.
- If players report timeouts, work through Troubleshooting container networking issues: bridge vs host mode in Docker.
- Watch CPU and memory while the world grows using Monitor Docker containers with Prometheus, cAdvisor and Grafana.
