Info: This tutorial assumes that you are familiar with the linux command line interface and vi. You will need to configure port forwarding or open network ports to allow steam and other players to connect to the server remotely. The server requires UDP ports 2456 - 2458 to be open in order for the connections to work successfully. This tutorial does not cover the networking portion.
Just copy and paste this below to setup prereqs for Ubuntu and docker repo.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
Now update apt to pull in the updated repositories, and install docker
sudo apt update
sudo apt install docker-compose docker-ce
Ensure docker will start on boot
sudo systemctl enable docker-ce
This setup leverages docker-compose to manage the container. This simplifies and clearly states the intention of this container, and allows it to be ran on any OS with docker and docker-compose installed.
For the compose file there are a few variables that need to be set.
Variable | Description |
---|---|
server_name | The name of your server to be displayed |
world | This is the name of the seed. It will generate two files matching the servers name ending with .db and .fwl example: server_name.db and server_name.fwl |
password | password to join the server |
public | 1 or 0 1 being public and 0 being private |
Run sudo vi /opt/valheim-compose.yml
to open the file and paste the contents below inside of the file.
version: '3'
services:
valheim_server:
image: steamcmd/steamcmd:latest
container_name: valheim_server
hostname: valheim_server
environment:
- templdpath=$LD_LIBRARY_PATH
- LD_LIBRARY_PATH=/data/linux64:$LD_LIBRARY_PATH
- SteamAppId=892970
- server_name="YOUR VALHEIM SERVER"
- world="Dedicated01"
- password=CHANGEME
- public=1
ports:
- 2456-2458:2456-2458/udp
networks:
steam-net:
ipv4_address: 10.0.0.3
restart: unless-stopped
command: ["/bin/bash"]
volumes:
- steam_stuff:/data
volumes:
steam_stuff:
networks:
steam-net:
ipam:
driver: default
config:
- subnet: 10.0.0.0/28
Copy contents below into the script with sudo vi /opt/server_start.sh
#!/bin/bash
ln -s /data/adminlist.txt /root/.config/unity3d/IronGate/Valheim/adminlist.txt
ln -s /data/bannedlist.txt /root/.config/unity3d/IronGate/Valheim/bannedlist.txt
ln -s /data/permittedlist.txt /root/.config/unity3d/IronGate/Valheim/permittedlist.txt
ln -s /data/prefs /root/.config/unity3d/IronGate/Valheim/prefs
ln -s /data/worlds /root/.config/unity3d/IronGate/Valheim/worlds
/data/valheim_server.x86_64 -name $server_name -port 2456 -world $world -password $password -public $public
Make the script executable
sudo chmod +x /opt/server_start.sh
Now that the files are in place the container can be started.
sudo docker-compose -f /opt/valheim-compose.yml up -d
This command will be used to update the server later as well.
sudo docker exec -it valheim_server bash -c "steamcmd +login anonymous +force_install_dir /data +app_update 896660 +quit"
sudo docker exec -it valheim_server bash -c "\
mkdir -p /root/.config/unity3d/IronGate/Valheim
mkdir -p /data/worlds
touch /data/{adminlist.txt,bannedlist.txt,permittedlist.txt,prefs}
"
sudo mv /opt/server_start.sh /var/lib/docker/volumes/opt_steam_stuff/_data/server_start.sh
Once the script is in place and all prereq files are present on the box you are now ready to start the script which launches the server. The server will managed by docker-compose via systemd.
Run vi /etc/systemd/system/valheim.service
to create and open the file, and paste in the contents below.
[Unit]
Description=Valheim Server
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
User=root
ExecStartPre=docker-compose -f /opt/valheim-compose.yml up -d
ExecStart=/usr/bin/docker exec valheim_server bash -c "/bin/bash /data/server_start.sh"
ExecStop=docker-compose -f /opt/valheim-compose.yml down
[Install]
WantedBy=multi-user.target
Since this service was just create you do not need to reload the daemon, but out of habit I usually do this anyway with
sudo systemctl daemon-reload
sudo docker-compose -f /opt/valheim-compose.yml down
sudo systemctl start valheim.service
sudo systemctl enable valheim.service
sudo systemctl status valheim.service
# updating
sudo docker exec -it valheim_server bash -c "steamcmd +login anonymous +force_install_dir /data +app_update 896660 +quit"
# restarting
sudo systemctl restart valheim.service
To run adhoc commands for troubleshooting run the command below to access the command prompt inside the container.
sudo docker exec -it valheim_server bash
You can then verify if the script start by looking for the symlinks. If the symlinks exist launch the server script to see what type of errors appear or verify where the server is failing from the output on the screen. Check for the symlinks to ensure the script was started
sudo docker exec -it valheim_server bash -c "ls -lah /root/.config/unity3d/IronGate/Valheim/"
Manually starting sript for troubleshooting
cd /data
./server_start.sh
The server can easily be migrated if created on a local workstation and wanting to move it to a public cloud provider or vice versa granted the new host has docker and docker compose installed.
To migrate the server you'll need gzip installed on both hosts or some other archiving tool. If you setup the systemd file you can shut the server down this way, otherwise manually shutdown the container.
sudo systemctl stop valheim
sudo docker save valheim_container | gzip | ssh <your_username>@<destination_ip_address> 'gunzip | sudo docker load'
zip -r steam_stuff.zip /var/lib/docker/volumes/opt_steam_stuff/_data
scp steam_stuff.zip ssh <your_username>@<destination_ip_address>:/home/<your_username>
Now login into the target machine and unzip the docker volume, and move it into the appropriate location with rsync. Go back over the installation process, and double check all prereqs are in place.
cd /home/<your_username>
unzip opt_steam_stuff.zip
sudo rsync -avr opt_steam_stuff/_data/ /var/lib/docker/volumes/opt_steam_stuff/_data
sudo systemctl start valheim