How to Run a FiveM Server with Docker: Technical Guide

FiveM Server with Docker – Hey there, fellow server owner! Are you tired of juggling dependencies, dealing with inconsistent server environments, or spending hours setting up a new server from scratch? If you’re nodding your head, you’ve come to the right place. There’s a powerful tool that can solve these headaches and more: Docker.

In this technical guide, we’re going to demystify the process and show you exactly how to run a FiveM server using Docker. We’ll break down containerization, walk you through the setup step-by-step, and give you the knowledge to manage your server like a pro. Let’s dive in!

Key Takeaways

  • Simplified Management: Docker streamlines the process of starting, stopping, and updating your FiveM server with simple commands.
  • Perfect Consistency: A Dockerized server runs in a predictable, isolated environment, eliminating the classic “it works on my machine” problem.
  • Dependency Freedom: All your server’s dependencies are packaged within the container, so you never have to worry about conflicts on your host machine.
  • Enhanced Portability: Easily move your entire server setup from one host to another without a lengthy reconfiguration process.
  • Scalability: Docker makes it much easier to deploy multiple instances of your server or scale your infrastructure as your community grows.

Why Use Docker for Your FiveM Server?

Before we get into the nitty-gritty, let’s quickly cover why this is such a game-changer. Traditionally, setting up a FiveM server involves installing a bunch of prerequisites directly onto your operating system. This can lead to version conflicts, messy uninstalls, and headaches when migrating to a new machine. Docker solves this by using “containers.”

Think of a container as a lightweight, self-contained box that holds everything your FiveM server needs to run: the server files (FXServer), your resources, your database connection, and all system dependencies. This box is completely isolated from your main operating system.

The benefits are huge:

    • Isolation: Run multiple servers on the same machine without them interfering with each other. Each has its own contained environment.

*Reproducibility: You can tear down and rebuild your server in seconds, and it will be exactly the same every single time. This is incredible for testing and development.

*Cleanliness: Your host machine stays clean. When you’re done with the server, you just remove the container, and it’s like it was never there. No leftover files or packages.

Prerequisites: What You’ll Need

To get started with your docker fivem server setup, you’ll need a few things in place first:

  • A server, either a Virtual Private Server (VPS) or a dedicated machine. We recommend a Linux distribution like Ubuntu 22.04.
  • Docker and Docker Compose installed on your server. DigitalOcean has excellent guides on this for most operating systems.
  • A valid FiveM License Key from the FiveM Keymaster.
  • Basic familiarity with the command line.
  • Your core server data files. If you’re starting fresh, check out our guide on how to create your own FiveM server to get the basics down.

Step-by-Step Guide to Your Docker FiveM Server Setup

Alright, let’s get our hands dirty and deploy fivem server docker style. Follow these steps carefully.

Step 1: Create Your Project Directory

First, connect to your server via SSH and create a folder that will hold all your configuration files and server data.

mkdir ~/fivem-server
cd ~/fivem-server
mkdir server-data

This creates a main directory `fivem-server` and a subdirectory `server-data` where we’ll store our resources and `server.cfg`.

Step 2: Create the Dockerfile

A `Dockerfile` is a text file that contains the instructions to build your server’s container image. It’s like a recipe. In your `fivem-server` directory, create a file named `Dockerfile`.

nano Dockerfile

Paste the following content into it. This script downloads the latest recommended FXServer build and sets it up.

# Use a base Linux image
FROM debian:buster

# Set environment variables for the FXServer version
ENV FIVEM_VERSION=5848-b35359e13d9615a9792476572626e95961a2d4a1

# Update packages and install dependencies
RUN apt-get update && apt-get install -y \
    curl \
    xz-utils \
    git

# Create the server directory
WORKDIR /server

# Download and extract the FXServer files
RUN curl -sSL "https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/${FIVEM_VERSION}/fx.tar.xz" | tar -xJ

# Expose the FiveM server port
EXPOSE 30120/tcp
EXPOSE 30120/udp

# Set the command to run the server
CMD ["/server/run.sh", "+exec", "server.cfg", "+set", "txAdminPort", "40120"]

Save and close the file (CTRL+X, then Y, then Enter in nano).

Step 3: Define Your Service with `docker-compose.yml`

Docker Compose helps you define and run multi-container applications. It simplifies the command-line arguments into a single configuration file. Create a file named `docker-compose.yml` in your `fivem-server` directory.

nano docker-compose.yml

This is the most important part of your fivem server docker configuration. Paste the following, making sure to replace `YOUR_LICENSE_KEY_HERE` with your actual FiveM license key.

version: '3.8'

services:
  fxserver:
    build: .
    container_name: fivem-server
    ports:
      - "30120:30120/tcp"
      - "30120:30120/udp"
      - "40120:40120/tcp"
    volumes:
      - ./server-data:/server/server-data
    environment:
      - FIVEM_LICENSE_KEY=YOUR_LICENSE_KEY_HERE
    restart: unless-stopped

This file tells Docker to:

  • Build an image from the `Dockerfile` in the current directory (`.`).
  • Map the necessary ports from the container to your host machine.
  • Mount your local `server-data` folder into the container. This is crucial for persistence! Your resources and config will live here, safe from container rebuilds.
  • Set your license key as an environment variable.
  • Automatically restart the server unless you manually stop it.

Step 4: Prepare Your Server Files

Now, populate your `server-data` directory. You’ll need at least your `server.cfg` file. You should also create a `resources` folder inside `server-data` for all your scripts.

This is where you’d add your chosen framework, like the popular QBCore Framework V8 or the reliable ESX Legacy Framework. Simply download and place their folders into your `~/fivem-server/server-data/resources` directory.

Step 5: Build and Run Your Server!

You’re all set! From your main `~/fivem-server` directory, run the following command to build your Docker image:

docker-compose build

Once it’s finished, you can start your server with:

docker-compose up -d

The `-d` flag runs the container in “detached” mode, meaning it will run in the background. Congratulations, you now run a FiveM server using Docker!

Managing Your Dockerized FiveM Server

Now that your server is running, here are a few essential commands for managing it:

  • View Logs: To see the server console output in real-time, use `docker-compose logs -f`.
  • Stop the Server: To gracefully stop and remove the container, use `docker-compose down`.
  • Start the Server: Just use `docker-compose up -d` again.
  • Restart the Server: A quick restart can be done with `docker-compose restart`.

Security and Best Practices

A stable server is a secure server. With your new setup, consider adding a robust FiveM anticheat to protect your community from modders and exploiters. The isolated nature of Docker already adds a layer of security, but in-game protection is still paramount.

Furthermore, a well-managed server opens the door to building a dedicated community. Once you have a loyal player base, you can consider monetization through a platform like Tebex to cover your server costs. You can even get started with a Free In-Game VIP Shop to integrate it seamlessly.

Conclusion

Embracing Docker for your FiveM server might seem daunting at first, but the long-term benefits in stability, portability, and ease of management are undeniable. You’ve learned how to create a reproducible environment, manage your server with simple commands, and structure your files for easy updates.

This setup provides a professional-grade foundation for you to build an incredible server. Now that the technical backend is solid, you can focus on the fun stuff: adding awesome scripts and building your community. Check out our shop for high-quality scripts like an Advanced Radio Script or a Free FiveM HUD to get started. For more guides and tips, be sure to explore our blog!