Running a Left 4 Dead 2 dedicated server in Docker keeps the game server and its files separate from the rest of your system. You will install the server files with SteamCMD, publish the required network ports, and configure a startup command and game settings. You will need a valid Steam account for installation and a machine that can stay online while people play.
What You’ll Need
- A Linux host with Docker Engine and the Docker Compose plugin, plus permission to run Docker commands.
- A Steam account and Steam Guard access if SteamCMD requests authentication. SteamCMD is used to download the dedicated-server files.
- At least several gigabytes of free storage, a stable internet connection, and enough CPU and memory for your player count and custom content.
- Access to your router or hosting-provider firewall if players will connect from outside your home network.
- The server’s public IP address or a DNS name to share with players.
Step-by-Step
- Check Docker. On the Linux host, run
docker --versionanddocker compose version. If either command is missing, install Docker Engine and its Compose plugin using the instructions for your Linux distribution. Make sure your account can run Docker, or prefix commands below withsudo. - Create a server directory. Choose a permanent location and create a folder for the Compose file and game data:
mkdir -p ~/l4d2-server/datacd ~/l4d2-server
The data folder will be mounted into the container so game files can persist when the container is replaced. - Choose and verify a container image. Use a maintained Linux image that documents support for the L4D2 dedicated server and SteamCMD. Read its documentation for the image name, required environment variables, data path, and startup command. Image interfaces differ; do not assume that variables or paths from another image will work. Check its maintenance status and published ports before pulling it.
- Write a Compose file for that image. Create
compose.yamlin the server directory. The general structure below shows the important Docker settings; replace the image, container path, and command with values documented by the image you selected:services:
l4d2:
image: YOUR_VERIFIED_IMAGE
container_name: l4d2
restart: unless-stopped
ports:
- "27015:27015/udp"
- "27015:27015/tcp"
- "27020:27020/udp"
volumes:
- ./data:/DOCUMENTED_CONTAINER_DATA_PATH
Some images install the game automatically; others require a SteamCMD command or configuration variables. Follow the selected image’s instructions, including any required Steam login settings. Avoid placing a Steam password directly in a file that may be shared or committed to source control. - Set the server configuration. Create or edit the image’s documented server configuration file, commonly a
server.cfgunder the game’sleft4dead2/cfgdirectory. Set a recognizable hostname, a suitable maximum player count, and any desired gameplay options supported by L4D2. For example, a server configuration may includehostname "My L4D2 Server"andsv_lan 0. Use the path inside the persistent data mount, not a temporary container-only location. - Start the container. From the directory containing
compose.yaml, rundocker compose up -d. The first launch may take time while SteamCMD downloads or validates the server files. Check progress withdocker compose logs -f; press Ctrl+C to stop following logs, not to stop the container. - Confirm the server started. Run
docker compose psand review the logs for SteamCMD completion and a game-server startup message. If the container exits or restarts repeatedly, inspect the first error in the logs before changing settings. Confirm that the configuration file is mounted where the image expects it. - Allow network traffic. Permit the published ports in the host firewall and any cloud firewall. Forward the same ports from your router to the host’s private IP if players connect over the internet. L4D2 commonly uses UDP port 27015 for game traffic and UDP 27020 for SourceTV; TCP 27015 may be useful for some server queries. Follow your image and server configuration documentation, and open only ports you need.
- Connect and test. From a client on the same network, open the in-game developer console and try
connect HOST_IP:27015. ReplaceHOST_IPwith the server’s LAN address for a local test, or its public address for an external test. If the server is private, configure its password as documented and share it only with intended players. - Keep it updated and manageable. Stop the service with
docker compose down; this does not remove the bind-mounted data. To update, follow the image’s documented update procedure, which may involve pulling a newer image or rerunning SteamCMD, then start it again withdocker compose up -d. Back up the data folder before significant updates or custom-content changes.
Common Mistakes
- Using the wrong port protocol. Game traffic normally relies on UDP. Publishing only TCP can leave the server unreachable even though the container appears healthy.
- Forwarding ports to the wrong machine. Router rules must point to the Docker host’s current private IP, not a player’s computer or a container IP.
- Assuming every image uses the same setup. Environment variables, paths, SteamCMD behavior, and required login methods vary. Follow the documentation for the exact image and tag.
- Editing files outside the persistent mount. Changes made only inside a replaceable container can disappear when it is recreated. Make sure configuration and game data are stored in the mounted host folder.
- Exposing unnecessary services. Do not publish ports or enable remote administration features unless you need them and understand their access controls.
Tips
- Pin a known image tag rather than automatically tracking an untested latest build, and read update notes before changing versions.
- Give the host a reserved LAN address so router forwarding does not break when its address changes.
- Keep your Compose file and configuration backed up, but exclude credentials and passwords from public repositories.
- Use
docker compose logs --tail=100for a quick recent log review, anddocker compose restartafter configuration changes if the image does not reload them automatically.
Troubleshooting
The container exits immediately: Run docker compose logs. Look for missing environment variables, a bad command, unsupported architecture, or a SteamCMD download or authentication failure. Correct the documented image settings, then run docker compose up -d again.
SteamCMD cannot download the server: Check that the host has internet and DNS access, that storage is not full, and that SteamCMD has completed any requested login or Steam Guard step. Some images support anonymous downloads; others require account authentication. Use the image’s instructions rather than assuming anonymous access works.
The server runs but players cannot connect: Verify the container is running, the host firewall permits the configured UDP ports, and router forwarding targets the correct host. Test from outside your home network; some routers do not support connecting to a public address from inside the same network. Also check that sv_lan 0 is set for internet play and that the server is listening on the expected port.
Configuration changes have no effect: Check the file path and volume mapping, confirm the file name and syntax, and inspect startup logs. Restart the service if necessary. A configuration file in the host folder will not be used if it is mounted to the wrong container directory.
Players see high latency or performance problems: Check host CPU and memory use, available upload bandwidth, and whether other workloads are competing for resources. Reduce custom content or player load and retest. Docker does not compensate for a slow or unstable network connection.
Frequently Asked Questions
Do I need a separate Steam account?
Not necessarily. SteamCMD may allow the server files to be downloaded anonymously, but some setups or downloads require account authentication. Use an account you control and follow the image’s current instructions.
Can I run the server on Windows or macOS?
Docker Desktop can run Linux containers on those systems, but networking and performance may differ from a Linux host. The steps here assume Docker Engine on Linux; check Docker Desktop and image documentation for platform-specific behavior.
Can friends connect without joining my LAN?
Yes, if the server is configured for internet play and the required ports are allowed through the host firewall, provider firewall, and router. Share your public IP or DNS name, not the container’s internal address.
Will my settings survive a container update?
They should if the configuration and game files are stored in the persistent host folder mounted as a volume. Verify the mapping and make a backup before updating.
How do I change the map or game mode?
Use the server console or the configuration and startup options supported by your chosen image and L4D2. Check the image documentation and game server commands, then restart or issue the appropriate command as required.
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
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches