keepcalculator

06 Numbers and Powers

CS2 Dedicated Server in Docker on a VPS

Card No. 06·73163 · Updated · Standard formula, shown below

This guide walks you through running a Counter-Strike 2 dedicated server inside a Docker container on a VPS. You’ll end up with a persistent, easily updatable game server that you can connect to from anywhere, with minimal overhead and no need to install SteamCMD directly on your host.

What You’ll Need

  • A VPS with at least 4 CPU cores, 8 GB RAM, and 40 GB of free disk space (SSD recommended).
  • Ubuntu 22.04 or 24.04 (other distros work but commands may differ).
  • Root or sudo access to the VPS.
  • Docker and Docker Compose installed. If not installed, follow the official Docker installation docs for your OS.
  • Ports 27015/tcp and 27015/udp open in your VPS firewall and your hosting provider’s control panel.

Step-by-Step

  1. Install Docker and Docker Compose (if not already present):
    sudo apt update
    sudo apt install -y docker.io docker-compose-v2
    sudo systemctl enable --now docker
  2. Create a directory for the server:
    sudo mkdir -p /opt/cs2 && cd /opt/cs2
  3. Create a Dockerfile that installs SteamCMD and downloads CS2 server files. Use the official SteamCMD image as a base:
    FROM steamcmd/steamcmd:ubuntu-24
    
    RUN steamcmd +force_install_dir /home/steam/cs2 +login anonymous +app_update 730 +quit
    
    EXPOSE 27015/tcp 27015/udp
    
    CMD ["/home/steam/cs2/game/bin/linuxsteamrt64/cs2", "-dedicated", "-console", "-usercon", "+map", "de_dust2", "+game_type", "0", "+game_mode", "1", "+sv_lan", "0"]
  4. Create a docker-compose.yml to define the service, set restart policy, and map ports:
    services:
      cs2:
        build: .
        container_name: cs2-server
        restart: unless-stopped
        ports:
          - "27015:27015/tcp"
          - "27015:27015/udp"
        volumes:
          - ./cs2-data:/home/steam/cs2
        environment:
          - STEAMAPPID=730
          - STEAMAPP=cs2
  5. Build and start the container:
    sudo docker compose up -d --build
  6. Verify the server is running:
    sudo docker logs cs2-server

    Look for lines like “Game server is ready” or “Connection to Steam servers successful”.

  7. Connect from Counter-Strike 2: Open the game, open the developer console (~), and type connect YOUR_VPS_IP:27015.
  8. Set a server password (optional): Add +sv_password yourpassword to the CMD in the Dockerfile, then rebuild.
  9. Update the server when a new game update arrives:
    cd /opt/cs2
    sudo docker compose build --pull
    sudo docker compose up -d

Common Mistakes

  • Forgetting to open UDP port 27015 in the VPS firewall or hosting provider’s security group. TCP alone is not enough.
  • Using the wrong SteamCMD app ID. CS2 uses 730, not 740 (which is CS:GO).
  • Not giving the container enough memory. CS2 servers can use 4-6 GB with many players or custom maps.
  • Putting the server files in a volume that is not persistent, causing re-downloads on every restart.
  • Running the server as root inside the container. The steamcmd image runs as user steam by default, so avoid overriding that.

Tips

  • Set a dedicated game server login token (GSLT) to avoid “No Steam Login” issues. Get one from Steam Game Server Account Management, then add +sv_setsteamaccount YOUR_TOKEN to the CMD.
  • Use a named volume instead of a bind mount for better performance on some filesystems.
  • Limit the server’s CPU and memory with Docker’s --cpus and --memory flags in the compose file to prevent it from exhausting the VPS.
  • Add a healthcheck to the compose file that pings the game port, so Docker can restart the container if it becomes unresponsive.
  • Keep the server files in a separate volume so you can update the container without re-downloading everything.

Troubleshooting

  • Server not appearing in the community list: Check that the GSLT is set, the server has a public IP, and the firewall allows incoming UDP. Also ensure +sv_lan 0 is set.
  • Connection timed out: Verify the VPS firewall and hosting provider’s network firewall allow port 27015/udp. Test with nc -vz YOUR_IP 27015 from your local machine.
  • Container exits immediately: Check logs with sudo docker logs cs2-server. Common causes: missing GSLT, wrong permissions on the volume, or insufficient disk space.
  • High CPU usage: Reduce the server’s tick rate or limit players with +maxplayers. Also consider using -high to raise process priority only if the VPS has spare cores.
  • Cannot write to the volume: Ensure the directory on the host has the correct ownership. Run sudo chown -R 999:999 /opt/cs2/cs2-data (999 is the steam user’s UID in the container).

Frequently Asked Questions

Do I need a GSLT token?

Yes, for a public server. Without it, the server may not appear in the community list and clients may get “No Steam Login” errors. It’s free to generate.

Can I run multiple CS2 servers on one VPS?

Yes, but each needs its own port and enough RAM/CPU. Create separate compose projects or use different ports in the same container.

How do I change the map?

Edit the +map argument in the Dockerfile CMD, then rebuild. Or use the in-game console command changelevel de_mirage if you have admin access.

How do I add a password?

Add +sv_password yourpassword to the CMD. Rebuild and restart the container. Players will need to enter it when connecting.

How do I update the server after a CS2 patch?

Run docker compose build --pull and then docker compose up -d. The server files will be re-downloaded inside the container.

Can I use a custom config file?

Yes, mount a config file into the container and add +exec server.cfg to the CMD. Place the file in the volume and reference it by name.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →