machete_kills

Dedicated Server Setup Guide on ANY platform (Windows/Mac/Linux) with Docker

Recommended Posts

There are several great guides on how to setup dedicated servers for each specific platform, and I’ve used them many times. When I was about to setup a dedicated server for myself from scratch for the 4th time, however, I decided to invest some more time instead and work on a reusable easy setup solution.

The goal was to have a platform-agnostic solution (something that runs in Linux, MacOS or Windows just the same) that would require only a few simple steps to get a proper server up and running. And by “proper” I mean a manageable server with Caves that supports Mods and customization, of course. 

The solution was developed using Docker and I’ve been playing on the server for a while quite happy with the result. I hope this project can help other people get started fairly fast and easily, having plenty of time to customize and play!

Please reach me out if come across any troubles while setting this up. Any feedback is deeply appreciated. The following are the instructions as they were posted on the Steam Guide. The most complete, detailed and up-to-date instructions will be found in the project's repository documentation on GitHub.

Setup Overview

The following are the macro steps that are required to get the dedicated server up and running:

  1. Pick a host machine
  2. Install the required tools:
    • Docker
    • Git (optional)
  3. Get the server files
  4. Set your Cluster Token

By completing the above you'll have a fully working server with caves ready to play! However it will obviously be running on default server and world configurations, no mods at all. You'll probably want to take some extra steps to:

  • Configure the server properties
  • Customize world generation
  • Install and customize mods

1. Pick a host machine

Spoiler

As mentioned, Docker runs on Windows, Mac OS X and several Linux distributions. Therefore you may pick the platform you like the best and feel comfortable with. Things to have in mind when selecting your host:

  • Have an exclusive machine to host the server to make sure resources will be promptly available to the server
    - You may of course host and play on the same machine. Just make sure you have the proper resources available!
  • One free CPU core per shard is recommended (2 in total, Master + Caves)
  • At least 1Gb RAM available per shard, + RAM for the running host OS. 
    - 2Gb should suffice for a server with only a few players (4 or less). 
    - 4Gb is the optimal for over 4 players
  • A "lightweight" Linux distribution is recommended to host for performance gains. Suggested distro: Debian 9

2. Install the required tools

Docker - Linux

Spoiler

Follow the official docs to install Docker on Linux. At first glance it might seem complicated, but the instructions are very detailed and thorough:

Docker - Mac / Windows

You only need the Docker desktop standalone as it has everything you need, no extra steps required. Voilà!

Git (optional)

Spoiler

If you want to install git to fetch the server files, it's super easy to install it in any OS.

In most Linux distros all you need is: 


sudo apt-get install git

 

3. Get the server files

Spoiler

If you installed Git, clone this repository in your home folder:


cd ~ && git clone https://github.com/mathielo/dst-dedicated-server.git

Alternatively you may simply download the zipped files from GitHub directly, then upload and extract it to your home folder.

4. Set your Cluster Token

Spoiler

The cluster token is stored in the cluster_token.txt file and without it your server won't run online. If you intend to run a LAN only server, you don't need this step. There are a few ways to generate and get a cluster token. You may follow what's in the existing cluster_token.txt file:


This file MUST be generated based on your Steam account. Enter the game and press "Play".
After you're logged in, bring up the console (by pressing `~`) and type the following command:

TheNet:GenerateServerToken()

Press enter. The console will go away, and a `cluster_token.txt` was generated in:
 - Unix: ~/.klei/DoNotStarveTogether
 - Windows: C:\Users\<your name>\Documents\Klei\DoNotStarveTogether

Get the generated file and OVERRIDE this one with the proper cluster token.

After you get it, make sure to delete all the content from this file and leave only your cluster token there, without any spaces or anything else.

You can easily do that replacing `InsertYourTokenHere` in the following command and executing it in your server:


echo 'InsertYourTokenHere' > ~/dst-dedicated-server/DSTClusterConfig/cluster_token.txt

Game Admin

The account that generates the token automatically gains admin access in-game, meaning you can rollback, regenerate the world or use console commands while playing.

Managing your server (start, stop, commands)

For simplicity of the `docker-compose` commands listed below, make sure you'll be running them from within the installation folder:

cd ~/dst-dedicated-server

Full reference can be found in the project's documentation.

Updating the game version

Spoiler

The developers are constantly updating the game, which is really good. However if your game client version mismatch the server's, you won't be able to see your server listed in Browse Servers. To updated the game client, simply stop and start the server again. On every startup the containers updates the game version automatically. Bear in mind this might take a minute or two.

Start the Server

Spoiler

From your installation folder, run docker-compose in detached mode to start the server


docker-compose up -d

Tip: You can follow logs when running in detached mode: 


docker-compose logs -f

 

Executing console commands

Spoiler

It's possible to execute game console commands from the terminal by attaching to the Master shard:


docker attach dst_master

Caution! Every input will be forwarded to the container when attached. That means if you hit CTRL-cthe container will receive SIGINT and will gracefully stop.

It's only possible to attach to the Master shard (dst_master container) as it's the one who manages the slave (Caves shard, dst_caves). i.e. Running c_shutdown() on the Master shard will shutdown allshards, while running it on Caves would shutdown the Caves shard only.Once attached, you may run any commands to manage the game such as c_save()c_spanw()c_regenerateworld(), etc.

Quote

To detach from the container, press the CTRL-p CTRL-q sequence. Hitting CTRL-c will stop the running container. Check Docker's attach docs for more info.

 

Stopping the Server

Spoiler

To save the game right before shutdown, attach to the container and execute c_shutdown():


docker attach dst_master
c_shutdown()

The Master shard will manage to save the game and send a shutdown signal to the Caves shard as well.

Alternative: shutdown without saving

If you simply want to shutdown the containers without saving the game:


docker-compose down

 

Installing Mods + Customizing the server

Please refer to the official docs for detailed information on how to:

Edited by machete_kills
Improving formatting, add missing section with links to mods + customization
  • Thanks 1

Share this post


Link to post
Share on other sites

dst_master    | [00:00:07]:     LOAD BE
dst_master    | /home/dst/start-container-server.sh: line 23:    38 Killed                  ./dontstarve_dedicated_server_nullrenderer -cluster DSTWhalesCluster -shard "$SHARD_NAME"
dst_master exited with code 137
 

Slight error, maybe something wrong in my shard config? I can tell you've been a lot of work into this tut, and I really appreciate it; but do you know how I can fix this error?

 

thanks

Share this post


Link to post
Share on other sites

Hey @Ceruleancerise, thanks for trying it out and reporting back! 

I just started out a fresh clone in my computer with the stock settings (as they are currently on the repository) and it worked without any issues. Couldn't reproduce the error you're getting, could you please provide more info about what OS you're using and what changes have you applied to the cluster config?

Regardless, when researching for the error message you got, it seems that the exited with code 137 means that your container ran out of memory. This is odd as starting a fresh container should take up very little memory, and even after playing for quite a while with a few players the usage doesn't go way beyond 0,5Gb (per container). See a server I've been hosting and playing with some friends for a while now:

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
1071790a9603        11.91%              516.6MiB / 3.856GiB   13.08%              19MB / 17.7MB       0B / 0B             13
8c2bba023c07        15.81%              631.7MiB / 3.856GiB   16.00%              19.5MB / 20MB       0B / 0B             14
Spoiler

The above was seen by running:


docker stats

When the command was executed there was no one playing on that server; If people were playing CPU usage would be higher. However memory usage doesn't vary too much whether there are people playing or not. 

So my wild guess here is that your Docker currently has limited memory to work with. See below some things you could try:

Check for other running containers usage

Docker engine usually has limited access to the computer's memory (it cannot/shouldn't consume all your computer's memory). Check if you have other containers running:

docker ps

If so, check their current memory usage:

docker stats

Try shutting down other containers if possible to free up some memory.

Check how much memory Docker engine has available to it

image.png.0a752220521348cc76adc86667ea393c.pngAccessing Docker Preferences > Advanced you should be able to see how much memory your system is making available for Docker (image to the right).

Thinking of the step above (checking for running containers), decide whether you should change your settings to reserve more memory to Docker.

Restart Docker

It could also be that some container has/had a memory leak and even after stopping it could be messing with the whole Engine's memory management. Just try restarting docker in that case, it's worth the try.

----

If none of the above solves your issue, please post the full startup log you get when running composer in attached mode:

docker-compose up

Please do also share other changes you may have done to the cluster.ini, Master/server.ini or Caves/server.ini files so we can dig further until we fix it! :)

Share this post


Link to post
Share on other sites

Sorry! I had completely disregarded the RAM requirements, as I'm running this on a DigitalOcean Droplet I only had 500MB to work with, however after adding 1G of SWAP space the container spins up perfectly :)

Also, this gave me some experience with Docker that I've been meaning to do for awhile.

Thanks bumches, huge vouch. 

 

EDIT: 

ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.

If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT
to a higher value (current value: 60).
 
I'll try a Droplet with better specs later I suppose, might fix this? 
Edited by Ceruleancerise

Share this post


Link to post
Share on other sites

Awesome! 

Regarding the COMPOSE_HTTP_TIMEOUT: Docker automatically has a low default timeout for when you are attached to containers. You can try increasing the time it takes to timeout, but that's not a solution.

Optimally you should run the containers in detached mode:

docker-compose up -d

This will start the containers but you won't see what's happening on the screen as you'll not be attached to them. This is very important also as if you're not running in detached mode and close your SSH/terminal session, the containers will be shut down. By running it in detached mode you can guarantee your containers / servers will be running in the background, regardless if you are connected (SSH'd) into the server or not.

Once they are running in detached mode, you can peek into what's happening by checking the logs:

docker-compose logs -f

Let me know how it's going when you start playing on it :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now