Skip to content

Latest commit

 

History

History

compose

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Source Dedicated Server (srcds) using Docker Compose

This example defines a basic set up for a Half-Life 2: Deathmatch server using the srcds image and Docker Compose.

A valid Steam account with Half-Life 2 purchased is required.

Project structure

.
├── docker-compose.yml
├── srcds.env
├── secret.txt
└── README.md
services:
  hl2mp:
    image: k4rian/srcds:latest
    container_name: hl2mp-server
    hostname: hl2mp-server
    command: -game hl2mp -console -secure -ip 0.0.0.0 +port 27015 +maxplayers 8 +map dm_overwatch
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - data:/home/steam/gameserver
    env_file:
      - srcds.env
    secrets:
      - srcds
    ports:
      - 27015:27015/tcp
      - 27015:27015/udp
    restart: unless-stopped

volumes:
  data:

secrets:
  srcds:
    file: ./secret.txt

The environment file srcds.env holds the server environment variables.

The Steam account password is defined in the secret.txt file.
— It will be mounted on /run/secrets/srcds within the container.
— The secret name has to be srcds.

To use an anonymous account, the secrets definitions in the compose file have to be omitted/commented out.

Deployment

docker compose -p hl2mp up -d

The project is using a volume in order to store the server files that can be recovered if the container is removed and restarted.

Expected result

Check that the container is running properly:

docker ps | grep "hl2mp"

To see the server log output:

docker compose -p hl2mp logs

Stop the container

Stop and remove the container:

docker compose -p hl2mp down

Both the container and its volume can be removed by providing the -v argument:

docker compose -p hl2mp down -v