Code Monkey home page Code Monkey logo

docker-srcds's Introduction

docker-srcds logo

A base Docker image for Valve's Source Dedicated Server (srcds) based on Debian (bookworm-slim) used to setup and run any Source Dedicated Server including Counter-Strike: Source (CSS), Left 4 Dead 1/2, Team Fortress 2, Garry's Mod and more.


Docker Tag Version Platform Description
latest 1.1 amd64 Base image
sftp 1.1 amd64 Base image with SFTP support
latest-buster 1.0 amd64 Base image (Buster) (Deprecated)
sftp-buster 1.0 amd64 Base image with SFTP support (Buster) (Deprecated)

Environment variablesSteam account authenticationStartup script argumentsUsage
Using ComposeCommon IssuesManual buildLicense

Environment variables

Some environment variables can be tweaked when creating a container to define the server application to interact with:

Variable Default value Description
APPID 232370 Steam application identifier (used by steamcmd).
APPNAME hl2mp Game name acronym (used by srcds).
STEAMACC_USERNAME anonymous (Optional) Steam account username.
STEAMACC_PASSWORD (Optional) Steam account password (NOT recommended, see the section below).

Default values will setup a Half-Life 2: Deathmatch Dedicated Server.

Steam account authentication

Some server applications require a valid Steam account in order for the files to be downloaded/updated and, in some cases, the corresponding game to be purchased/added on the said account.
The credentials can be provided using environment variables or a Docker secret (password only).

It is strongly recommended to create a new account (or use a secondary one) with a dedicated email and Steam Guard disabled. Do NOT use your main account!

See the Dedicated Servers List on the Valve Developer Wiki for more information about each server requirements.

The STEAMACC_USERNAME environment variable holds the Steam account username.

The (clear, unencrypted) Steam account password can be defined by:

  • Bind mount a text file containing the password into the container.

    • The mountpoint path has to be /run/secrets/srcds.
    • This is the recommended method. See the fourth example usage in the section below.
  • Using the STEAMACC_PASSWORD environment variable when creating the container.

    • This method is NOT recommended for production since all environment variables are visible via docker inspect to any user that can use the docker command.

Startup script arguments

A convenient script has been added to interact with steamcmd and srcds in various ways. It will intercept the first passed argument and do the following:

  • -s|-start
    • Starts the server using srcds_run
    • Will fail if the server files haven't previously been downloaded
  • -u|-update
    • Downloads/updates the server files using steamcmd
  • -v|-validate
    • Downloads/updates and validate the server files using steamcmd
  • -to|takeown
    • Recursively changes ownership of all server files to the steam user
    • Useful if you have altered any file permission outside the container file system
  • -c|-steamcmd
    • Invokes steamcmd directly without interacting with srcds
  • [none]
    • Downloads/updates the server files if they haven't previously been downloaded
    • Starts the server in auto-update mode (using -autoupdate, -steam_dir and -steamcmd_script arguments)

Usage

Example 1:
Setup and run a Counter-Strike: Source public server:
Since no recognized argument is passed to the startup script, the server will start using the auto-update feature and also auto-restart if it crashes

docker run -d \
  --name css-serv \
  --net=host \
  -e APPID=232330 \
  -e APPNAME=cstrike \
  -i k4rian/srcds \
  -console \
  -secure \
  -port 27015 \
  -maxplayers 10 \
  +map de_dust2

Example 2:
Download and validate the Left 4 Dead 2 Dedicated Server files to a named volume for further use:
The container will be deleted immediately after the task is completed
Notice the -validate argument passed to the startup script

docker run --rm \
  -e APPID=222860 \
  -e APPNAME=left4dead2 \
  -v l4d2serv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -validate

Now we can create a named container to start the server (in co-op mode) using the previously created volume:
Since the -start argument is given, the startup script won't trigger any update

docker run -d \
  --name l4d2serv \
  --net=host \
  -e APPID=222860 \
  -e APPNAME=left4dead2 \
  -v l4d2serv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -start \
  -console \
  -secure \
  -port 27015 \
  +map c1m1_hotel \
  +maxplayers 4

If we want to perform a manually update (without validating the files), we can use an ephemeral container to handle the task:
The container will be deleted immediately after the task is completed
Notice the -update argument passed to the startup script

docker run --rm \
  -e APPID=222860 \
  -e APPNAME=left4dead2 \
  -v l4d2serv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -update

Finally, if the server has permission issues with some files, we can use an ephemeral container again to recursively change ownership of all server files:
The container will be deleted immediately after the task is completed
Notice the -takeown argument passed to the startup script

docker run --rm \
  -v l4d2serv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -takeown

Example 3:
Setup and run a Team Fortress 2 Dedicated Server and store all the files inside a named volume created on the fly:
The startup script will perform a update check (without validation) on each start
You need a valid GSLT token to make the server reachable

docker run -d \
  --name tf2serv \
  --net=host \
  -e APPID=232250 \
  -e APPNAME=tf \
  -v tf2serv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -console \
  -secure \
  -timeout 0 \
  -port 27015 \
  +randommap \
  +maxplayers 24 \
  +sv_pure 1 \
  +sv_setsteamaccount {GSLT_TOKEN}

Example 4:
Setup and run a No More Room In Hell Dedicated Server using a valid Steam account:
In this example, the password is stored in the secret.txt file located in the current working directory.
The game has to be present on the Steam account or the installation will fail

docker run -d \
  --name nmrihserv \
  --net=host \
  -e APPID=317670 \
  -e APPNAME=nmrih \
  -e STEAMACC_USERNAME="{VALID_STEAM_USERNAME}" \
  -v "$(pwd)"/secret.txt:/run/secrets/srcds:ro \
  -v nmrihserv_data:/home/steam/gameserver \
  -i k4rian/srcds \
  -console \
  -secure \
  -maxplayers 8 \
  -port 27015 \
  +map nmo_broadway

Using Compose

See compose/README.md

Common Issues

See COMMON_ISSUES.md

Manual build

Requirements:
— Docker >= 18.09.0
— Git (optional)

Like any Docker image the building process is pretty straightforward:

  • Clone (or download) the GitHub repository to an empty folder on your local machine:
git clone https://github.com/K4rian/docker-srcds.git .
  • Then run the following command inside the newly created folder:
docker build --no-cache -t k4rian/srcds:latest .

License

MIT

docker-srcds's People

Contributors

k4rian avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.