Hosting game servers using Docker on a VPS makes the setup clean, consistent, and easy to manage. In this guide, we use a fresh Ubuntu 24.04 or Ubuntu 22.04 and turn it into a powerful game server host for real servers, including Minecraft, Steam or Source-based games, Valheim, and Palworld.
We know that configuring a VPS can be complex. If you want a pre-configured VPS, PerLod Hosting offers game-optimized VPS plans with this entire stack pre-configured.
Requirements for Hosting Game Servers Using Docker on a VPS
We want to set up a few details to prepare our Ubuntu server for hosting game servers, including VPS firewall, Docker networking, and filesystem layout.
Tip: While this guide will walk you through the entire process, if you'd prefer a pre-optimized, game-ready VPS with this exact stack already configured, check out our high-performance VPS Hosting Plans.
Prepare the VPS for Hosting Game Servers
We start by preparing the VPS by installing essential tools, configuring the firewall, and setting up the correct timezone. This setup keeps your VPS secure and ready for Docker and game servers.
Run the system update and upgrade with the following command:
Bash
sudoaptupdate&&sudoaptupgrade-y
Install the required tools on your server with the command below:
Enable UFW firewall and check its status with the commands below:
Bash
sudoufwenablesudoufwstatus
Install Docker Engine and Compose Plugin
At this point, you must install Docker and Docker Compose. Docker will containerize each game server, which keeps them isolated and easy to manage, and Docker Compose allows defining multi-container servers in a single file.
Add Docker's official repository and install it with the following commands:
Host mode: Uses the VPS network directly, reducing latency for some games.
You can start with bridge mode, which maps only the ports you need, and try host mode if your Steam or Source server has connectivity or latency issues.
Create a shared bridge network for container DNS with the command below:
Bash
dockernetworkcreategames-net||true
This network ensures servers can talk to each other if needed.
Deploy Minecraft Java Game Server
Minecraft is the most popular Java server. To deploy the game server, we use the itzg/minecraft-server image for easy setup.
Create a docker-compose.yml in /opt/game-servers/minecraft/ with the following command:
YAML
1cat >/opt/game-servers/minecraft/docker-compose.yml <<'YAML'2services:3mc:4image: itzg/minecraft-server:latest5container_name: mc6restart: unless-stopped7networks:8- games-net9ports:10-"25565:25565/tcp"11environment:12EULA:"TRUE"13TZ: ${TZ:-UTC}14# Choose one of these types; PAPER is a great default:15TYPE: PAPER16# Version (optional; empty = latest compatible):17VERSION:"1.21.1"18# Memory limits inside JVM:19MEMORY:"4G"20# Optional: enable online mode (true = Mojang auth). For testing on LAN, set to FALSE.21ONLINE_MODE:"TRUE"22# Optional: initial server properties:23MOTD:"Dockerized Minecraft Server"24ENABLE_COMMAND_BLOCK:"true"25volumes:26- ./data:/data27- /etc/localtime:/etc/localtime:ro28healthcheck:29test:["CMD","mc-monitor","status","--host","localhost"]30interval: 30s31timeout: 10s32retries:63334networks:35games-net:36external:true37YAML
Open firewall port for it with the command below:
Bash
sudoufwallow25565/tcp
Navigate to the Minecraft game server directory:
Bash
cd/opt/game-servers/minecraft
Export the env file and run the Minecraft game server with the commands below:
Everything is persisted in /opt/game-servers/minecraft/data.
Deploy Generic Steam or Source Game Server Template
This template uses SteamCMD to install or update a server on container start and then launch it. You can reuse it for CS2, Valheim, ARK, and others by setting environment variables. You will need the following factors:
Then, create a start.sh file, which installs or updates the server and then launches it:
Bash
cat>/opt/game-servers/steam-generic/start.sh<<'BASH'#!/usr/bin/env bashset-euopipefail:"${APP_ID:?APP_ID not set}":"${APP_DIR:=serverfiles}":"${VALIDATE:=false}":"${ADDITIONAL_STEAMCMD_ARGS:=}":"${START_CMD:?START_CMD not set}"STEAMCMDDIR="${STEAMCMDDIR:-/opt/steamcmd}"SERVERDIR="${SERVERDIR:-/home/steam/serverfiles}"echo"[INFO] Running SteamCMD update/install for app ${APP_ID} (validate=${VALIDATE})"VALIDATE_FLAG=""if["${VALIDATE}"="true"];thenVALIDATE_FLAG="validate"fi"${STEAMCMDDIR}/steamcmd.sh"+@sSteamCmdForcePlatformTypelinux\+loginanonymous\+force_install_dir"${SERVERDIR}"\+app_update"${APP_ID}"${VALIDATE_FLAG}${ADDITIONAL_STEAMCMD_ARGS}\+quitecho"[INFO] Launching: ${START_CMD}"cd"${SERVERDIR}"execbash-lc"${START_CMD}"BASH
Now set up a docker-compose.yml with correct APP_ID, START_CMD, and ports with the command below:
YAML
1cat >/opt/game-servers/steam-generic/docker-compose.yml <<'YAML'2services:3steam-server:4build: .5container_name: steam-server6restart: unless-stopped7networks:8- games-net9environment:10TZ: ${TZ:-UTC}11# --- COMMON ENV ---12APP_ID:"730"# EXAMPLE: replace with your game's dedicated server AppID13APP_DIR:"serverfiles"14VALIDATE:"false"# set "true" occasionally15ADDITIONAL_STEAMCMD_ARGS:""# e.g. "-beta public -betapassword yourpass"16# START_CMD MUST be adapted to your title:17# Example (Source-style — replace map, gamemode, etc.):18START_CMD:"./game/bin/server_binary -dedicated +map de_inferno -tickrate 128 -gameport 27015 -ip 0.0.0.0"19volumes:20- ./data:/home/steam/serverfiles21ports:22-"27015:27015/udp"23-"27015:27015/tcp"24-"27020:27020/udp"2526networks:27games-net:28external:true29YAML
Adjust the firewall rules with the following commands:
Note: For host networking for lower latency and fewer NAT quirks, you can change the compose service:
YAML
1network_mode:"host"2ports:[]# remove ports section when using host mode
Then, remove the external network under that service. With host mode, open the exact ports on the VPS firewall because there’s no Docker NAT. To do this, you can run:
You can prevent a single game server from using too much CPU or RAM by adding the following config:
YAML
1deploy:2resources:3limits:4cpus:'2.0'5memory: 6g
Note: deploy is used by Swarm. For Compose alone, some runtimes still apply cgroup limits. Alternatively, you can use:
YAML
1mem_limit: 6g2cpus:2.0
Compose v2 still accepts these service-level keys for cgroup constraints.
Conclusion
By following this guide, you have successfully transformed a basic Ubuntu VPS into a powerful, organized, and secure platform for hosting multiple game servers using Docker.
We hope you enjoy this Hosting Game Servers Using Docker on a VPS guide. Subscribe to our X and Facebook channels to get the latest articles.
Docker provides isolation, ensuring that each game server runs in its own contained environment. This prevents conflicts between dependencies, makes updates and rollbacks easier, and simplifies management.
Bridge Mode (Default): Docker creates a private internal network for containers, and you must manually map ports. This is more secure and ideal for running multiple game servers on one VPS.
Host Mode: The container shares the VPS's network stack directly, eliminating the NAT layer. This can reduce latency and solve connectivity issues for some Steam/Source games, but it is less isolated.
It is recommended to start with Bridge mode and switch to Host only if you experience problems.
The best resource is the official SteamDB site. Search for your game and look for the "App ID" of the dedicated server tool, not the client game.
We use cookies to run PerLod and to understand how the site is used. You can accept everything, or open Manage to turn individual categories off. Cookie policy.