Half-Life
Недостатньо оцінок
Running a Half-Life Dedicated Server with Docker
Автор: Jimo
This guide will walk you through the process of running a Half-Life Dedicated Server with Docker.
   
Нагородити
До улюбленого
В улюблених
Прибрати
Introduction
This guide will walk you through the process of running a Half-Life Dedicated Server with Docker.

If you're unfamiliar with Docker, it's a tool that lets you run applications in isolated environments, known as containers. These containers ensure consistency and portability by containing all the dependencies and configurations needed to run an application. As a result, you can run the container on any machine with Docker installed and be confident that the application will run consistently, regardless of who runs it or where it's run, so long as the system architecture has support. When it comes to building a dedicated server with Docker, it is a great option, as all it takes to set one up is a series of terminal commands and a basic knowledge of how Half-Life organizes its game directories.

Requirements 📝
Before starting, ensure you have the Docker daemon and the Docker CLI tool installed and available. You can find links to these below.


You can verify that you have everything installed correctly by opening your systems terminal (Command Prompt, PowerShell, Bash, etc) and typing docker -v. You should get some sort of log back with information about which version you have installed.

If these steps don't work, refer back to the Docker setup guide for troubleshooting.
Getting Started 🚀
The following steps will not work if you use an ARM architecture system. For best results, use a system running x86-64.


To start the server we'll be using a pre-built image available on Dockerhub[hub.docker.com] (the images are alternatively available on the GitHub Container Registry[github.com]). These pre-built images contain all of the necessary dependencies and configurations needed to start a server as quickly as possible. The source code for these images can be found on GitHub[github.com].

To get started, run the following command in your terminal. Adjust the image name (jives/hlds) so the tag corresponds with the game you want to use. Additionally, you can adjust the server startup arguments by modifying the command property; for a list of available arguments, visit the Valve Developer Wiki.

docker run -d -ti \ --name hlds \ -v "$(pwd)/config:/temp/config" \ -v "$(pwd)/mods:/temp/mods" \ -p 27015:27015/udp \ -p 27015:27015 \ -p 26900:26900/udp \ -e GAME=${GAME} \ jives/hlds:valve \ "+log on +rcon_password changeme +maxplayers 12 +map crossfire" # 📣 Modify your server startup commands here. You can specify the image with the desired game you want the server to run in the line above.

Once the command finishes running, you can connect to your server via the machines public IP address by loading the game on Steam. If you cannot join the server, you can check for errors in the server logs by running docker ps to get the container id followed by docker logs <container id>. Additionally you may need to forward UDP ports 27015 and 26900.



Available Images

The available game images are below. When changing the game, be sure to adjust the +map parameter, as it may cause the server not to be joinable if the map is unavailable. For example, crossfire is not an available map when you're starting a Counter-Strike server.


Using Docker Compose 🎼
If you'd prefer to use Docker Compose[docs.docker.com], simply create a docker-compose.yml file somewhere on your system, and place the following within it. Modify all of the settings as you see fit.

services: hlds: # 📣 Adjust the image value here with the desired game you want the server to use. image: jives/hlds:valve volumes: - "./config:/temp/config" - "./mods:/temp/mods" ports: - "27015:27015/udp" - "27015:27015" - "26900:2690/udp" environment: - GAME=${GAME} # 📣 Modify your server startup commands here. command: +log on +rcon_password "changeme" +maxplayers 12 +map crossfire

Within your terminal, navigate to where the docker-compose.yml file is located and run docker compose up.
Server Configs and Plugins 🔌
If you wish to add server configurations, such as add-ons, plugins, map rotations, etc, you can add them to the config directory. Your directory setup should look something like the following where you're running either docker run or docker compose next to where the config directory is located.

├── 📂 server │ ├── 📜 docker-compose.yml │ ├── 📂 config │ │ ├── 📜 mapcycle.txt │ │ ├── 📜 motd.txt │ │ ├── 📂 maps | │ | ├── 📜 crazytank.bsp

The config directory is volume-mapped within the directory for the game for which you're starting the container. For example, if you're starting a container for cstrike, you can add things like mapcycle.txt or motd.txt here, and it would appear within the corresponding cstrike directory within the container.

The config directory should be volume mapped to /temp/config, for example ./config:/temp/config, once the container starts it will re-write the files into the correct place so the Half-Life Dedicated Server client recognizes them.

The startup examples posted in this guide already have this directory volume mapped accordingly. If you've strayed from the suggested setup, please refer back to it to get started.

├── 📦 hlds │ ├── 📂 cstrike │ │ ├── 📂 maps | │ | ├── 📜 crazytank.bsp │ │ ├── 📜 mapcycle.txt │ │ ├── 📜 motd.txt

  1. Create a folder called config alongside where you would typically start the server process.
  2. Add your config files to the directory.
  3. Start the image as you usually would, either with docker run or docker compose up.

Tip: You can use this method to install server plugins such as AMX Mod, Meta Mod, etc., as the directory can handle nested folders too; for example, these can be placed in config/addons/amxmodx etc.
Custom Mods 🔧
If you want to run a custom mod, you can do so with the mods directory. Your directory setup should look something like the following where you're running either docker run or docker compose next to where the mods directory is located.

├── 📂 server │ ├── 📜 docker-compose.yml │ ├── 📂 mods │ | ├── 📂 decay │ │ | ├── 📜 autoexec.cfg │ │ | ├── 📂 models │ │ | ├── 📂 maps │ | ├── 📂 svencoop

The mods directory is volume mapped within the root directory of the Half-Life Dedicated Server client on startup. For example, if you wanted to add a mod named decay, you'd place it as a subfolder here, i.e., mods/decay. Once the container starts, it would be placed in the following directory within the container.

The mods directory should be volume mapped to /temp/mods, for example ./mods:/temp/mods, once the container starts it will re-write the files into the correct place so the Half-Life Dedicated Server client recognizes them.

The startup examples posted in this guide already have this directory volume mapped accordingly. If you've strayed from the suggested setup, please refer back to it to get started.

├── 📦 hlds │ ├── 📂 cstrike │ │ ├── 📂 models │ │ ├── 📂 maps │ │ ├── 📜 autoexec.cfg │ ├── 📂 valve │ │ ├── 📂 models │ │ ├── 📂 maps │ │ ├── 📜 autoexec.cfg │ ├── 📂 decay │ │ ├── 📂 models │ │ ├── 📂 maps │ │ ├── 📜 autoexec.cfg │ ├── 📂 svencoop │ │ ├── 📂 models │ │ ├── 📂 maps │ │ ├── 📜 autoexec.cfg

  1. Create a folder called mods alongside where you would normally start the server process.
  2. Add your mod files as a sub-directory of mods. For example if the mod name is decay, you'd place it in mods/decay.
  3. Define the GAME environment variable for your mod name. The dedicated server client will use this to ensure that it starts a server for the correct mod, which corresponds with the directory name that was just created.
    export GAME=decay
  4. Start the image as you usually would, either with docker run or docker compose up. Most Half-Life mods require specific startup arguments. For more details, refer to the Valve Developer Wiki and the instructions for the mod you're trying to run.

Tip: You'll likely want to use the valve base image (jives/hlds:valve) when starting a custom Half-Life mod.
Closing Notes
If you have any questions or comments regarding this guide please feel free to leave a comment below, or post an issue on GitHub[github.com].

You can also check out all of my other Steam Guides here.
Коментарів: 4
Доцент 2 жовт. о 5:51 
cool :polycrown:
Jimo  [автор] 2 жовт. о 5:17 
Haha typically I would not have as I've mostly moved on from it, but this project seemed to be pretty relevant to share here.
lightwo 2 жовт. о 1:48 
(Referring to Steam guide system)
lightwo 2 жовт. о 1:47 
It's been nearly 10 years, but alas you still write guides. :p

That's dedication, I've made a number of them but figured the system is unreliable enough it makes more sense to use just about anything else to publish information like this.

In any case, thank you for posting the guide.