Running Valheim on Dokku

Written Mar 03, 2023
Return to index

Valheim is a Viking-themed, multiplayer survival game that’s a fun game to play with friends. Think Viking-Minecraft and you wouldn’t be too far off. Since I’m going skiing this weekend, I figured I’d set up a server for my friends to continue our game while I’m gone.

Viking ship in a natural harbor
Sailing in Valheim is essential, as its the only way to move metal.

We can easily host Valheim on Dokku, a Heroku clone (and much more) that you can self-host and is great for hosting all your little projects. We’re going to use it to host Valheim in 5 minutes. I’m going to assume you’ve already got Dokku running, so we won’t cover the setup.

Step one, create the application:

dokku apps:create valheim

Step two, mount the volumes to store the game’s save files and configuration somewhere they’ll persist between updates and reboots:

dokku storage:mount valheim /var/lib/dokku/data/storage/valheim/valheim/server:/home/steam/valheim
dokku storage:mount valheim /var/lib/dokku/data/storage/valheim/valheim/saves:/home/steam/.config/unity3d/IronGate/Valheim

Step three, disable the default nginx proxy, since the game uses UDP to communicate and (currently) Dokku’s proxy can’t handle this:

dokku proxy:disable valheim

Step four, because we’re not using Dokku to manage the ports, we need to tell Dokku to turn off our old containers completely when we deploy new versions. If we don’t do this, deploying new versions will fail because the ports are already in use:

dokku checks:disable valheim

Step five, manually map our ports to the world. The default port for Valheim is 2456, so this is probably what you want to use. Whatever port you pick, you also need to expose the next two ports.

dokku config:set valheim DOKKU_DOCKERFILE_PORTS="2456"
dokku docker-options:add valheim deploy "-p 2456:2456/udp -p 2457:2457/udp -p 2458:2458/udp"

Step six, set the environment variables. Update these as required:

dokku config:set --no-restart valheim NAME="My Valheim Server
dokku config:set --no-restart valheim WORLD="MyWorld"
dokku config:set --no-restart valheim PASSWORD="LetsPlay"
dokku config:set --no-restart valheim TZ="America/Chicago"
dokku config:set --no-restart valheim PUBLIC="1"
dokku config:set --no-restart valheim AUTO_UPDATE="0"

And finally, deploy the application:

dokku git:from-image valheim mbround18/valheim:latest

And that’s it! You now have a working Valheim server running on dokku.