Valheim – dedicated server using docker

Valheim – dedicated server using docker 1 - steamlists.com
Valheim – dedicated server using docker 1 - steamlists.com
Finally a valheim dedicated server that’s easy to set up and no crazy bash scripts that do a ton of extra, and unnecessary, stuff.
This docker image is ready to use as is and can be set up in about a minute if you know what you are doing.

This image is read for deployment on your favorite docker orchestration platforms, such as kubernetes or swarm. It uses industry standard practices to ensure all configurations can take pace using environment variables; you can even use docker/kube/etc secrets to secure your sensitive data.

 
 

Overview

 

Motivation for this project

By trade, I’m a cloud and automation engineer. I don’t claim to be the best, but I know a thing or two. One thing I know, is docker is where it’s at. It’s a bit difficult to understand at first, but it makes your life easier in the end. 
 
I’ve looked over most of the guides and docker images out there. However, they all do unnecessary stuff and overcomplicate things imo. So, I wanted to share my project. I hope this is useful to the community and can act as a template for future steam/linux servers. 
 

Source Code

I highly recommend you check the readme, as this code repo is the “source of truth” for all documentation and code. 
My public GitLab repo can be found in the below link. Feel free to submit any issues with the docker container/deployment instructions. 
 
https://gitlab.com/japtain_cack/valheim-server 
 

Docker Repo

Just in case you want to know where docker images come from 
 
https://hub.docker.com/r/nsnow/valheim-server 
 
 
 

Prerequisite

 
 
 
 

Create a volume

 

Create the directory

To have a persistent world, you must create a volume on the host where docker is running. 
 
mkdir /mnt/docker/valheim/world1 
 

Set the directory permissions

You can set the user id and group id to whatever suits your needs. However, if you want to define a custom user, you will need to determine the user and group id, then set them using the below instructions. See: Server properties and environment variables. 
 
chown -R 1000:1000 /mnt/docker/valheim 
 
 
 

Run the dedicated server

Use this docker run command to launch a container and customize the start.sh. 
Replace <ENVIRONMENT_VARIABLE>=<VALUE> with the appropriate values (see section “Server properties and environment variables”) 
 
Do not simply copy/paste this command. Understand what is going on first! 
docker run -d -it –name=valheim \ 
-v /opt/valheim/world1:/home/valheim/server \ 
-p 2456-2458:2456-2458/tcp \ 
-e VALHEIM_NAME=”valheim” \ 
-e <ENVIRONMENT_VARIABLE>=<VALUE> \ 
nsnow/valheim-server:latest 
 
Here is what is happening: 

  • docker run: this is telling docker to run a container. 
  • -d: disconnected, run in background. You will want this to run it “as a service”. 
  • -i: keep STDIN open even if not attached. 
  • -t: allocate a pseudo-TTY. 
  • you will need the “-it” if you wish to connect to the bash shell on the container for some reason. 
  • –name: sets the container name. 
  • -v: sets the volume mount. This binds a container directory to a directory on your local system. 
  • -p: sets the port bindings 
  • -e: sets environment variables. This flag can be used multiple times as needed.

 
 
 
 

Is that it?

That’s it, you’re done. You can continue reading past this point, but it’s simply additional information and help beyond this point. 
 
 
 

Additional docker commands

kill and remove all docker containers 
docker kill $(docker ps -qa); docker rm $(docker ps -qa) 
 
docker logs 
docker logs -f valheim 
 
attach to the valheim server console 
Use ctrl+p then ctrl+q to quit. 
docker attach valheim 
 
exec into the container’s bash console 
docker exec valheim bash 
 
NOTE: referencing containers by name is only possible if you specify the –name flag in your docker run command. 
 
 
 

Set selinux context for mounted volumes

You only need this if you are running selinux in enforcing mode 
 
sudo chcon -Rt svirt_sandbox_file_t /path/to/volume 
 
 
 

Server properties and environment variables

Set user and/or group id (optional) 
 
VALHEIM_UID=1000 
VALHEIM_GUID=1000 
 
https://gitlab.com/japtain_cack/valheim-server/-/blob/master/remco/templates/start.sh 
Use this file for the full environment variable reference. 
 
This project uses Remco config management
This allows for templatization of config files and options can be set using environment variables. 
This allows for easier deployments using most docker orchistration/management platforms including Kubernetes. 
 
The remco tempate uses keys. This means you should see a string like “/valheim/some-option” within the getv() function. 
 
This directly maps to a environment variable, the / becomes an underscore basically. The other value in the getv() function is the default value. 
 
For instance, “/valheim/some-option” will map to the environment variable VALHEIM_SOME-OPTION. 
 
getv(“/valheim/some-option”, “default-value”) 
 
becomes 
 
docker run -e VALHEIM_SOME-OPTION=my-value … 
 

Written by Japtain Cack

Hope you enjoy the Guide about Valheim – dedicated server using docker, if you think we should add extra information or forget something, please let us know via comment below, and we will do our best to fix or update as soon as possible!
 
 
 
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*