Skip to content

Instantly share code, notes, and snippets.

@Darkhogg
Last active January 26, 2018 07:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darkhogg/5f970a3bcc8eb59ed60311dfd65febdc to your computer and use it in GitHub Desktop.
Save Darkhogg/5f970a3bcc8eb59ed60311dfd65febdc to your computer and use it in GitHub Desktop.
Factorio Headless Server on Dokku

Factorio Server on Dokku

This document and associated files describe a very simple procedure to push a Dokku application that will launch a Factorio Multiplayer Server. This are the actual files used to launch my Factorio server, so you should trust that it works.

Dokku Setup

In order for the instructions on this document to work, you need to use Dokku v0.5.0 or greater.

Setting up and configuring Dokku is out of scope of this document, but there are plenty of resources online to do so. I personally use the DigitalOcean's One-click Dokku Droplet, but you may use any provider you want.

App Configuration

Before we push the application to Dokku, it's a good idea to configure a few things to make it work correctly:

  1. Create the application:

    dokku apps:create factorio
    
  2. Define a storage volume for the saves directory so your map persists across deploys:

    dokku storage:mount factorio /var/lib/dokku/data/storage/factorio/saves:/opt/factorio/saves
    
  3. Disable Nginx proxying, as we're not using HTTP for anything:

    dokku proxy:disable factorio
    
  4. Set up port forwarding:

    dokku docker-options:add '-p 34197:34197/udp'
    

    If you intend to use RCON, remember to also forward the RCON (TCP) port.

App Deployment

In order to deploy, you just need to clone this Gist, add the Dokku remote and push. As simple as that. You might want to check the Dockerfile and modify the Factorio version or the list of mods, though.

There are, however, a few configuration values you might want to set via dokku config:set:

  • FCT_SERVER_NAME: The server name, as shown in the server browser.
  • FCT_SERVER_DESCRIPTION: The server description, as shown in the server browser.
  • FCT_SERVER_MAX_PLAYERS: The server maximum number of players. Defaults to 0.
  • FCT_SERVER_VISIBILITY: The visibiility of the server: public, lan or hidden. Defaults to hidden.
  • FCT_SERVER_PASSWORD: The game password needed to access the server.
  • FCT_SERVER_VERIFY: Whether to verify connected players for a valid factorio.com account.
  • FCT_SERVER_PORT: Port in which the server will be bound. Defaults to 34197. NOTE This is the internal port, not really useful with port forwarding.
  • FCT_SERVER_COMMANDS: Whether to allow commands in the game: true, false or admins-only. Defaults to admins-only.
  • FCT_SERVER_AUTOSAVE_SLOTS: Number of slots of autosaved games. Defaults to 5.
  • FCT_SERVER_AUTOSAVE_INTERVAL: Number of minutes between autosaves of the game. Defaults to 3.
  • FCT_SERVER_LATENCY: Latency of the game, in milliseconds. Defaults to 150.
  • FCT_SERVER_AUTOKICK_INTERVAL: Number of minutes until an AFK player is kicked. Defaults to 0 (no AFK kicks).
  • FCT_ACCOUNT_USERNAME: Your factorio.com username, necessary for public games.
  • FCT_ACCOUNT_PASSWORD: Your factorio.com password, necessary for public games.
  • FCT_ACCOUNT_TOKEN: Your factorio.com authentication token, which can be used instead of the password.
  • FCT_RCON_PORT: The port in which to listen for RCON connections and commands. NOTE This is the internal port, not really useful with port forwarding.
  • FCT_RCON_PASSWORD: Password for RCON connections.
FROM ubuntu:16.04
MAINTAINER Daniel Escoz <darkhogg@gmail.com>
# Install and update the necessary software
RUN apt-get update \
&& apt-get install -y curl xz-utils\
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Factorio Headless -- Modify the URL to download a different version of the game
RUN curl -L -o /tmp/factorio.tar.xz https://www.factorio.com/get-download/0.15.34/headless/linux64 \
&& tar -xJf /tmp/factorio.tar.xz -C /opt \
&& rm -f /tmp/factorio.tar.xz
# Finish
ADD run.sh Procfile /app/
WORKDIR /app
server: ./run.sh
#!/bin/bash
set -e
fct_root=/opt/factorio
fct_bin="$fct_root"/bin/x64/factorio
fct_save="$fct_root"/saves/default.zip
fct_settings="$fct_root"/data/server-settings.json
cd "$fct_root"
printf ' · Creating settings file...\n'
cat >"$fct_settings" <<EOF
{
"name": "${FCT_SERVER_NAME:-Factorio}",
"description": "${FCT_SERVER_DESCRIPTION:-Another Factorio Server}",
"max_players": ${FCT_SERVER_MAX_PLAYERS:-0},
"visibility": "${FCT_SERVER_VISIBILITY:-hidden}",
"username": "${FCT_ACCOUNT_USERNAME}",
"password": "${FCT_ACCOUNT_PASSWORD}",
"token": "${FCT_ACCOUNT_TOKEN}",
"game_password": "${FCT_SERVER_PASSWORD}",
"verify_user_identity": ${FCT_SERVER_VERIFY:-true},
"allow_commands": "${FCT_SERVER_COMMANDS:-admins-only}",
"autosave_interval": ${FCT_SERVER_AUTOSAVE_SLOTS:-5},
"autosave_slots": ${FCT_SERVER_AUTOSAVE_INTERVAL:-10},
"akf_autokick_interval": ${FCT_SERVER_AUTOKICK_INTERVAL:-0},
}
EOF
printf ' · Creating map if needed...\n'
if ! [ -f "$fct_save" ]; then
"$fct_bin" --create "$fct_save"
fi
fct_opts=( \
--start-server-load-latest \
--port "${FCT_SERVER_PORT:-34197}" \
)
# Append option for server settings
if [ -f "$fct_settings" ]; then
fct_opts+=(--server-settings "$fct_settings")
fi
# If RCON password is set, append options
if [ -n "$FCT_RCON_PASSWORD" ]; then
fct_opts+=(--rcon-port "${FCT_RCON_PORT}")
fct_opts+=(--rcon-password "${FCT_RCON_PASSWORD}")
fi
printf ' · Launching server...\n'
"$fct_bin" "${fct_opts[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment