Running Game Servers in Docker Containers on VPS
Why Docker for Game Servers?
Docker containers provide isolated environments for each game server — no dependency conflicts, clean Java versions per server, easy cloning for testing, and consistent behavior across machines. For a VPS running multiple game servers (e.g., Minecraft + FiveM + CS2), Docker prevents resource conflicts and makes adding/removing servers trivial. Each container gets its own: file system, network namespace, and resource limits. This is the production-standard approach for multi-server VPS hosting.
Installing Docker and Docker Compose
On Ubuntu 24.04: 'sudo apt update && sudo apt install -y docker.io docker-compose-v2'. Add your user to the docker group: 'sudo usermod -aG docker $USER' (log out and back in). Verify: 'docker run hello-world'. Install Portainer for web-based container management: 'docker run -d -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest'. Access Portainer at https://yourserverip:9443.
Minecraft Docker Setup
Use the itzg/minecraft-server image — the most popular and well-maintained Minecraft Docker image. docker-compose.yml example: 'version: "3.8" services: minecraft: image: itzg/minecraft-server:latest container_name: minecraft ports: - "25565:25565" environment: EULA: "TRUE" TYPE: "PAPER" VERSION: "1.21" MEMORY: "4G" volumes: - ./minecraft-data:/data restart: unless-stopped'. Customize: change TYPE to FORGE, FABRIC, or PURPUR; set MEMORY to match your allocation; add MODPACK_PLATFORM and MODPACK_ID for auto-installing modpacks.
Multiple Game Servers with Docker Compose
Run multiple game servers from a single docker-compose.yml. Define each as a separate service with unique: container_name, ports (Minecraft 25565, FiveM 30120, CS2 27015), volumes (separate data directories), and MEMORY limits. Use Docker's resource constraints: 'deploy: resources: limits: cpus: "2.0" memory: 4G'. This prevents any one server from hogging all CPU/RAM. Monitor total resource usage with 'docker stats' or Portainer's dashboard.
Networking and Port Management
Game servers need specific ports exposed to the internet. In Docker, map host ports to container ports: '25565:25565/tcp' for Minecraft, '30120:30120/tcp' and '30120:30120/udp' for FiveM, '27015:27015/udp' for CS2. For multiple Minecraft instances, increment host ports: container1 uses 25566:25565, container2 uses 25567:25565. Update firewall rules for each port. Consider using Docker networks for inter-server communication (e.g., BungeeCord proxy to backend servers).
Backup and Disaster Recovery
Docker simplifies backups: each server's data lives in its volume mount. Backup with rsync or restic: 'rsync -avz /opt/game-servers/minecraft-data /backup/minecraft-$(date +%Y%m%d)/'. Schedule via cron. To restore: stop the container, restore the data folder, start the container. Docker images are disposable — all persistent data is in volumes. This means you can recreate a container from docker-compose.yml in seconds on any machine with Docker installed.
FAQ
Related Tutorials
Was this guide helpful?
Join our Discord for more guides and direct help from our engineering team.
