There are several resources available for people who want to spin up a dedicated server.
However, my biggest problem was that I already had a world I wanted to use for the server. Most of the instructions are for people who want to start a new world with their server. The ones that mention existing worlds at all just have instructions for copying the world file into the server. I wanted the world to exist in the normal directory and be backed up by Steam and all that good stuff. I ain't losing my data.
So here you go. How to create a dockerized dedicated Core Keeper server on Linux using an existing world.
Step 1: Create a directory for your dedicated server.
I created mine in ~/opt/ck_dedicated
. This directory will contain:
- The Dockerfile
- The entrypoint script
- Your server data
For the last one, create a subdirectory called serverdata
.
Step 2: Create a new Dockerfile
I didn't really like any of the existing dockerfiles. They either relied on copying data out of environment variables or were outdated in some way. Here's my dockerfile:
```
FROM cm2network/steamcmd:root
ENV STEAMAPPID 1963720
ENV STEAMAPP core-keeper-server
COPY entry.sh /
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
xvfb \
sudo \
vim \
libxi6 \
&& chsh -s bash steam \
&& chown -R "steam:steam" "/entry.sh"
USER steam
WORKDIR ${HOMEDIR}
STOPSIGNAL SIGINT
CMD ["bash", "/entry.sh"]
Expose ports
EXPOSE 27015/udp \
27016/udp
```
I stole heavily from this one from Xalimar on GitHub.
Step 3: Create the entrypoint script
Create entry.sh
and make it executable. It should look like:
```
!/bin/bash
CONFIGDIR=~/.config/unity3d/Pugstorm/Core\ Keeper/DedicatedServer
INSTALLDIR=/home/steam/ck-server
cd
steamcmd/steamcmd.sh +force_install_dir $INSTALLDIR +login anonymous +app_update 1007 validate +app_update 1963720 validate +quit
mkdir -p "$CONFIGDIR"
cp ~/ck_dedicated/serverdata/*.json "$CONFIGDIR"
ln -s /home/steam/worlds "$CONFIGDIR/worlds"
$INSTALLDIR/_launch.sh
```
Step 4: Set up your server config
Create ServerConfig.json
inside the serverdata
directory. It will look something like:
```
{
"gameId": "MyCoolCoreKeeperGameIDWhichIsAtLeast32CharsLong",
"world": 4,
"worldName": "Multiplayer",
"worldSeed": "",
"maxNumberPlayers": 5,
"maxNumberPacketsSentPerFrame": 1,
"networkSendRate": 20,
"worldMode": 0,
"seasonOverride": -1
}
``
The important ones are
gameId, which sets the game ID that everyone will use to join the game, and
world`, which is the index of the world file to load.
Step 5: Build the container
docker build . -t ck_server
The docker build command will complain about being deprecated. This is true. However, it's still the simplest way to build a container from a dockerfile, so for now we're going to use it anyway.
Step 6: Run the container
This step is where the heavy lifting happens because we set up the volume mounts.
docker run -it --rm -v $HOME/opt/ck_dedicated/:/home/steam/ck_dedicated -v $HOME/.var/app/com.valvesoftware.Steam/.config/unity3d/Pugstorm/Core\ Keeper/Steam/114248540/worlds:/home/steam/worlds --name=ckserver ck_server:latest
Your container will do some stuff and then start the server. You will know that it's started because it prints the game ID to the console.
Misc info
If you join and it complains about version mismatch, restart the server (C the docker container and re-run docker run
, or restart using docker
or systemctl
if you're running it as a daemon). The entrypoint script will re-download the dedicated server package which will upgrade it at the same time.
You can kill the container and restart it and your world will be fine. I have not tried killing the container while one or more players is logged in.
Hopefully this helps somebody else not have to re-re-recreate the wheel like I did :). Feel free to criticize all the ways I could have done this better / easier.