Containerizing a dedicated Valheim server using Docker and Docker Compose represents the modern deployment standard for cooperative multiplayer worlds. Running game infrastructure inside an isolated container eliminates dependency debugging on the host Linux distribution, simplifies cross-server world migrations, and enables automated SteamCMD patch downloads on release.
This comprehensive guide details authoring a docker-compose.yml manifest using the production-tested lloesche/valheim-server image, mapping host volumes for persistent world storage, enabling crossplay for Xbox consoles, and tuning container stop timeouts to prevent world corruption.
Preparing Host Storage Directories for Persistence#
Containers are ephemeral: any data written to container-local layers is destroyed when images update or restart. All game world databases (.db and .fwl), BepInEx plugins, and server configurations must reside on persistent host storage mounts.
Initialize directory trees and assign file permissions:
mkdir -p /opt/valheim/config /opt/valheim/data && sudo chown -R 1000:1000 /opt/valheim
The /opt/valheim/config path holds your world saves and configurations, while /opt/valheim/data stores cached Steam game files.
Authoring the docker-compose.yml Manifest#
Create /opt/valheim/docker-compose.yml with the following service declaration:
services:
valheim:
image: lloesche/valheim-server
container_name: valheim-server
restart: unless-stopped
stop_grace_period: 2m
ports:
- "2456-2457:2456-2457/udp"
environment:
- SERVER_NAME=VikingKingdom
- WORLD_NAME=Dedicated
- SERVER_PASS=SecretPass123
- SERVER_PUBLIC=true
- SERVER_ARGS=-crossplay
- UPDATE_CRON=0 4 * * *
volumes:
- /opt/valheim/config:/config
- /opt/valheim/data:/opt/valheim
Key configuration parameters explained:
stop_grace_period: 2m— An essential requirement. Valheim requires sufficient time to serialize active binary structures into.dbfiles during shutdown. Docker's default 10-second timeout sends a prematureSIGKILL, corrupting active worlds.SERVER_ARGS=-crossplay— Enables the PlayFab backend network relay to support Xbox One and Series X/S cross-platform joins.UPDATE_CRON=0 4 * * *— Built-in cron scheduler checks for new SteamCMD updates nightly at 04:00.
Firewall Configuration for UDP Transport#
The Valheim network stack communicates across two consecutive UDP transport ports:
sudo ufw allow 2456:2457/udp
TCP ports do not require exposure.
Deploying the Game Server Container#
Switch to the configuration directory and launch the service in the background:
cd /opt/valheim && docker compose up -d
Docker will pull the base image, execute SteamCMD to download server binaries, and initialize world generation.
Inspecting Container Logs and Join Codes#
Monitor initialization output in real time:
docker compose logs -f valheim
A healthy startup confirms operation with Game server connected and outputs your 16-character connection Join Code.
If you prefer operating a high-availability Valheim server without managing Docker manifests, firewall port forwards, or container storage mappings, specialized Valheim game hosting provides instant server provisioning and cloud backups from an intuitive dashboard.




