Skip to content

bnerickson/civ5_server_docker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

civ5_docker_server

Scripts and Dockerfiles to install and run a dedicated Civilization 5 server on a headless Linux machine.

Major Fork Changes

  1. This fork runs on a fedora container.
  2. All AWS-specific statements have been removed in favor of optional nfty (see https://docs.ntfy.sh/) and/or Discord notifications (see https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) that are fired off when a player disconnects and on a weekly basis. The latter uses a different database based on players that have clicked "Next Turn" ergo it is more accurate. However, because it's trivial to spam notifications this way, it is only triggered weekly on the backend.
  3. x11vnc has been removed in favor of x0vncserver because remotely connecting to the former in the fedora container was not working for me.
  4. WINE/Proton are "sandboxing" by default, so the "My Games" directory is now in the specific wine prefix as opposed to /root.
  5. winetricks and umu-launcher are installed from repos as opposed to being compiled.
  6. WINEARCH=win32 has been removed. It is deprecated and its replacement--WoW64--is feature-complete in WINE.
  7. Steam installed via winetricks.
  8. Eliminate requirement for Steam to run in the background while Civ5 is running.
  9. Steam initial execution (to grab required DLLs) now works because CEF (chromium) features are now disabled.
  10. Added ability to define custom dnf repos.
  11. Added script utilizing xdotool to automatically reload the most recent autosave when the server is started.
  12. (Optional) Runs with a dedicated GPU to offload some processing from the CPU.
  13. (Optional) Ability to apply CPU limiting to the CivilizationV.exe.

How does it work? (briefly)

Civ 5 Server is a Windows-only GUI application that needs to render frames with OpenGL Direct3D (translated to OpenGL with wine). This Docker setup creates a virtual X11 framebuffer for Civ to render to, provides a VNC server so you can remote in, and installs Mesa such that the CPU can render frames. However, in this branch a GPU is used to offload the graphics processing.

The attempt_autostart.bash script will, using xdotool and precise mouse coordinates based on the fixed 1920x1080 desktop resolution (though 1600x900 is also supported via manual Dockerfile change), select the latest autosave and automatically start the server. This takes place every time the server is started either when the container starts normally or when Civilization V crashes and restarts. If there is no autosave present, then the server must be configured manually via the GUI via VNC before it will start. Therefore, if you wish to start and configure a brand new game, be sure to delete the old autosaves in the ./civ5save/Saves/multi/auto directory first.

When was this last tested

This fork was last tested and working 2026/05/18 with fedora:44 running Proton-GE 10.34. GPU support has only been tested with AMD RX and Intel Iris GPUs (in particular the Radeon RX 550 and Intel Iris Plus Graphics 655).

Known Issues / TODO:

None

Instructions

1. Clone this repository on your Linux server git clone https://github.com/bnerickson/civ5_server_docker as a non-root user with sudo priviledges and enter the cloned directory with cd civ5_server_docker

2: Install Civilization V and the Civilization V SDK (CivilizationV_Server.exe) into the civ5game directory using the provided install script as follows: ./install_civ.sh <steam_username> <steam_password>

Note that sometimes steam_cmd can SEGFAULT for no apparent reason, but re-running the install script over and over until the installs complete is a valid, if annoying, workaround. You can also copy the files over manually, but using the install script is recommended.

3: (Optional) Get your GPU's PCI BusNumber:DeviceNumber.FunctionNumber from the output of lspci (e.g. 00:02.0).

4: Build the container prerequisites with the following command: ./build.sh.

4a: (Optional) When prompted, enter in the GPU PCI BusID determined in the step above or leave blank to use the dummy driver (NO GPU-offload) [Default: ff:ff.ff, which uses the dummy driver].

4b: (Optional) When prompted, enter in the CPU limit value if you would like to restrict CivilizationV from using ALL of your processing. This value is measured as a percentage of ALL cores on your system. For instance, if you have 8-core processor and want to use a maximum of 4-cores of processing power, enter in "400" [Default: maximum_percentage_of_all_cores, no limit in other words]

5: For all other customizations, see the following:

5a: (Optional) If you wish to notify users of turn status via nfty, setup a nfty notification topic (see https://docs.ntfy.sh/ for details on how this is done). Add the chosen notification topic name to ./server/ntfy_topic.txt with no empty newlines below it. If left empty it will not be used.

5b: (Optional) If you wish to notify users of turn status via a Discord webhook, setup a webook in the channel of your choice (see https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks for instructions on how this is done). Add the resultant webhook ID and webhook Token values to the ./server/discord_webhook_id.txt and ./server/discord_webhook_token.txt files respectively with no empty newlines below them. If left empty it will not be used.

5c: (Optional) If you wish to use a custom fedora.repo, fedora-cisco-openh264.repo, or fedora-updates.repo file, create and/or paste them into the server/ directory. If the files do not exist then the Docker build process will use the public Fedora repositories. This can help speed up container image build times dramatically if a local dnf mirror is available.

5d: (Optional) If you wish to edit the time spent waiting for Steam to auto-update during container construction, update the STEAM_INSTALL_SLEEP_TIMER argument in ./server/docker-compose.yml. This might be necessary if you have a slow Internet connection or slow server in-general. If Steam does not install successfully, this is the first place to look (default: 120s).

5e: (Optional) If you wish to set the default frame rate that the GUI runs at to a custom value, update the DXVK_FRAME_RATE variable in ./server/civ5.env [Default: 2, that is 2fps].

5f: (Optional) If you wish to set the version of ProtonGE to download and install, update the GE_PROTON_VERSION argument in ./server/docker-compose.yml in the format GE-Proton<version> (Ex: GE-Proton10-29) (default: latest, the latest version of GE-Proton).

6: Build and launch the container with the command docker compose -f ./server/docker-compose.yml up (it should take 7-10 minutes to build). If the build crashes when installing/running Steam via winetricks, rebuilding the container again by re-running the command is often enough to fix the issue.

7: After the container starts running, you should be able to remote in with VNC. The container is setup to only allow connections from localhost, so you'll want to open up an SSH tunnel if you are remoting in from a different machine (Ex: ssh -NL 5900:127.0.0.1:5900 ${USERNAME}@${SERVER_IP}).

8: Setup the game through the VNC connection. The mouse cursor WILL jump around because it is attempting to autostart (ignore it). Make sure port forwarding is setup (see Port Forwarding section below) and users should be able to connect to your game.

systemd Integration

The following is an example systemd service defintion I use to manage the container (/etc/systemd/system/docker.civ5.service):

[Unit]
Description=Docker Civilization V Service
After=docker.service
Requires=docker.service

[Service]
Type=simple
WorkingDirectory=/home/game/containers/civ5_server_docker/server
ExecStart=/usr/bin/docker compose --file docker-compose.yml up
ExecStop=/usr/bin/docker compose --file docker-compose.yml down
TimeoutStartSec=0
Restart=always

[Install]
WantedBy=multi-user.target

Replace the WorkingDirectory=/home/game/containers/civ5_server_docker/server line in the service definition with the path to your ./server directory, run the systemctl daemon-reload command, then run the systemctl start docker.civ5.service command to build/start the container.

Port Forwarding

27016 UDP is the only port you need to allow incoming traffic through. If you're just using plain iptables or nftables as a firewall, bringing up the docker container should open that port for you.

Credits

A big thanks goes out to:

  1. https://gitlab.com/Cerothen
  2. https://github.com/Andrew-Dickinson
  3. https://gitlab.com/CraftedCart
  4. https://gitlab.com/Hexarmored

Without their work/forks this would not work at all.

The Proton-GE script is modified from this repo (thanks, jerluc):

About

https://github.com/bnerickson/civ5_server_docker

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • Shell 63.6%
  • Dockerfile 19.7%
  • Python 8.7%
  • templ 8.0%