Ahorra hoy mismo en 20%. Usa el código WELCOME al finalizar la compra. WELCOME

Cómo ejecutar un servidor FiveM usando Docker

Lista de verificación rápida para la configuración de Docker de FiveM

Una configuración útil de Docker mantiene los datos de txAdmin persistentes, expone los puertos correctos y hace que las actualizaciones sean reversibles.

  • Usa Docker Compose v2 y monta por bind-mount txData o el directorio de datos de tu servidor.
  • Expón 30120 TCP/UDP para FiveM y 40120 solo donde se requiera acceso a txAdmin.
  • Haz una copia de seguridad de server.cfg, resources, txData y los datos de la base de datos antes de cambiar artifacts o imágenes.

Rutas de tienda relacionadas: Paquetes de servidor | Scripts FiveM | Herramientas de administración

Despliega un servidor FiveM confiable con Docker Compose: instala, configura server.cfg, abre puertos, persiste datos y gestiona actualizaciones.

Resumen

  • Instala Docker Engine + Docker Compose v2 en Ubuntu. (Documentación de Docker)
  • Crea una carpeta de proyecto, agrega .env (set CLAVE DE LICENCIA, SERVER_NAME, puertos) y un compose.yaml.
  • Empezar con docker compose up -d; monitorea los registros con docker compose logs -f.
  • Editar data/server.cfg (hostname, endpoints, resources); reinicia el contenedor.
  • Abre el firewall para 30120/TCP+UDP y 40120/TCP (txAdmin). El puerto predeterminado de txAdmin es 40120. (Documentación de Cfx.re)
  • Siempre ejecuta el contenedor con stdin/tty habilitado para evitar bloqueos. (GitHub)

Prerrequisitos

  • Sistema operativo: Linux Ubuntu 22.04+ (notas para macOS/Windows abajo).
  • Hardware: 2+ vCPU, 4–8 GB de RAM (más para recursos pesados), Unidad de estado sólido recomendado.
  • Docker: Instalar Docker Engine y Compose v2 desde la documentación oficial. (Documentación de Docker)
  • Clave de licencia FiveM: Generar en el portal Cfx.re (Keymaster). Mantenerla en secreto. (soporte.cfx.re)
  • Firewall/NAT: Capacidad de abrir/reenviar puertos 30120 (TCP+UDP) y opcionalmente 40120 (TCP). (Documentación de Cfx.re)
  • (Opcional) Un dominio/subdominio para txAdmin.

Descripción general de la arquitectura

Un contenedor ejecuta Servidor FX usando la imagen spritsail/fivem Los datos están montados por enlace to persist servidor.cfg, resources, and logs. Ports 30120/TCP+UDP are exposed to players; 40120/TCP exposes txAdmin when enabled. A healthcheck can probe http://127.0.0.1:30120/info.json. (GitHub)

+-------------------- Docker Host (Ubuntu) --------------------+
|  /home/fivem/data  -->  /config   (in container)            |
|  /home/fivem/txData --> /txData   (txAdmin data)            |
|                                                            |
|  Exposed: 30120/tcp+udp  [FXServer]  |  40120/tcp [txAdmin] |
|  Healthcheck: GET 127.0.0.1:30120/info.json                 |
+-------------------------------------------------------------+

Quick Start (copy-paste)

1) Create a project folder

# Optional: dedicated system user and directories
sudo useradd -r -m -d /home/fivem -s /usr/sbin/nologin fivem || true
sudo mkdir -p /home/fivem/{data,txData}
sudo chown -R "$USER":"$USER" /home/fivem
cd /home/fivem

2) Create .env

cat > .env <<'EOF'
# === REQUIRED ===
LICENSE_KEY=REPLACE_WITH_YOUR_CFX_KEY

# Convenience (used by ports mapping below)
FXSERVER_PORT=30120
TXADMIN_PORT=40120

# Not read by the image directly; use it when editing server.cfg
SERVER_NAME="My Docker FiveM"

# Optional: if omitted, default config generation sets a random RCON password
RCON_PASSWORD=
EOF

3) Minimal compose.yaml (pin a tag)

Smallest working setup using the upstream image. Uses tty+stdin to prevent crash. (GitHub)

# compose.yaml
services:
  fivem:
    image: spritsail/fivem:stable
    container_name: fivem
    environment:
      - LICENSE_KEY=${LICENSE_KEY}
      # Optional toggles (see table below):
      # - NO_DEFAULT_CONFIG=1   # required if you want to use txAdmin
      # - NO_LICENSE_KEY=1      # if you put the key in server.cfg instead
      # - NO_ONESYNC=1          # disable OneSync in default config
      # - RCON_PASSWORD=${RCON_PASSWORD}
    volumes:
      - ./data:/config         # server.cfg, resources, logs
    ports:
      - "${FXSERVER_PORT}:30120/tcp"
      - "${FXSERVER_PORT}:30120/udp"
    tty: true                  # prevent startup crash (equiv. to -t)
    stdin_open: true           # prevent startup crash (equiv. to -i)
    restart: unless-stopped

Start it:

docker compose up -d
docker compose logs -f

4) Extended variant (txAdmin, healthcheck, limits)

# compose.extended.yaml
services:
  fivem:
    image: spritsail/fivem:stable
    container_name: fivem
    environment:
      - LICENSE_KEY=${LICENSE_KEY}
      - NO_DEFAULT_CONFIG=1       # enable txAdmin (no default +exec)
      # - NO_LICENSE_KEY=1        # if storing key in server.cfg
      # - RCON_PASSWORD=${RCON_PASSWORD}
    volumes:
      - ./data:/config
      - ./txData:/txData          # persist txAdmin data
    ports:
      - "${FXSERVER_PORT}:30120/tcp"
      - "${FXSERVER_PORT}:30120/udp"
      - "${TXADMIN_PORT}:40120/tcp"  # txAdmin Web UI (default 40120)
    tty: true
    stdin_open: true
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:30120/info.json >/dev/null 2>&1"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s
    # Basic resource knobs for standalone Compose (not Swarm 'deploy')
    cpus: 2
    mem_limit: "6g"
    ulimits:
      nofile:
        soft: 1048576
        hard: 1048576
    restart: unless-stopped

Si wget is unavailable in the image, remove the healthcheck or replace with a TCP probe. txAdmin persists under /txData, port 40120 is its default. (GitHub)


Configuration & Persistence

  • On first run, defaults are written to the bind mount ./data (container path /config). Edit ./data/server.cfg and restart the container. (GitHub)

Typical servidor.cfg bits:

# data/server.cfg
# Network endpoints (leave 0.0.0.0 to listen on all interfaces)
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# Server name
set sv_hostname "My Docker FiveM"

# License key (use this only if NOT using LICENSE_KEY env)
# sv_licenseKey "REPLACE_WITH_YOUR_CFX_KEY"

# Example: ensure a basic resource
# ensure chat

Directory layout (host):

/home/fivem
├─ data/            -> /config     (server.cfg, resources/, logs/)
└─ txData/          -> /txData     (txAdmin profiles & DB)

Backups

  • Bind-mount backup:
tar -C /home/fivem -czf fivem-backup_$(date +%F).tgz data txData
  • If you switch to named volumes, back up like:
docker run --rm -v fivem_data:/data -v "$PWD":/backup busybox \
  sh -c 'tar -czf /backup/fivem_data_$(date +%F).tgz -C / data'

Environment variables (from imagen spritsail/fivem)

NombreObjetivoEjemplo
CLAVE DE LICENCIARequerido FiveM server license key to start FXServerLICENSE_KEY=xxxxx
RCON_PASSWORDRCON password used when creating default configs; random 16-char if unsetRCON_PASSWORD=strongpass
NO_DEFAULT_CONFIGDisable default +exec so txAdmin can manage the server1
NO_LICENSE_KEYDon’t read key from env; keep it in servidor.cfg1
NO_ONESYNCDisable OneSync in default configs1

These env vars and paths /config, /txData, plus the need for -ti are defined by the upstream image. (GitHub)

Secret manejo: Prefer NO_LICENSE_KEY=1 and put sv_licenseKey en servidor.cfg with correct file permissions if you don’t want the key in the container env. (GitHub)


Networking & Security

Required ports

ObjetivoPortProto
Player connections / API30120TCP+UDP
txAdmin Web UI (optional)40120TCP
Legacy master (rarely needed)30110UDP

FiveM defaults to 30120; txAdmin’s default is 40120. (GitHub)

UFW examples (Ubuntu)

sudo ufw allow 30120/tcp
sudo ufw allow 30120/udp
sudo ufw allow 40120/tcp   # only if you enable txAdmin
sudo ufw reload

nftables (example ruleset extract)

sudo nft add table inet filter
sudo nft add chain inet filter input '{ type filter hook input priority 0; policy drop; }'
sudo nft add rule inet filter input ct state established,related accept
sudo nft add rule inet filter input iif lo accept
sudo nft add rule inet filter input tcp dport {30120,40120} accept
sudo nft add rule inet filter input udp dport 30120 accept

Least privilege & secrets

  • Run on a hardened host; avoid mapping extra capabilities; don’t run Docker as raíz user on the host.
  • Mantener RCON enabled only if needed; protect txAdmin with strong credentials and restrict access at the firewall.
  • If you use SELinux-based distros (not Ubuntu), add :Z/:z to bind mounts to fix context issues.

Updates & Rollbacks

Update to latest pinned tag

docker compose pull
docker compose up -d

Pin by digest (immutable)

# Pull and discover the digest of the current tag
docker pull spritsail/fivem:stable
docker inspect --format='{{index .RepoDigests 0}}' spritsail/fivem:stable
# Use the printed value in compose, e.g.:
# image: spritsail/fivem@sha256:abcdef...

Rollback

  • Change the image reference back to the previous tag/digest and docker compose up -d.
  • Keep recent image digests with docker image ls --digests.

The image provides estable y el último tags; prefer estable for fewer surprises. (GitHub)


Monitoring & Maintenance

  • Estado: docker ps, docker compose ps
  • Registros: docker compose logs -f
  • Stats: docker stats fivem
  • Healthcheck: Polls info.json; remove/adjust if tooling missing. (Documentación de Cfx.re)
  • Disk: docker system df, prune old images if needed.
  • Backups: Cron the tar command in “Configuration & Persistence”.

Solución de problemas

  • Invalid license key: Verify in Cfx.re portal and ensure only one server is using the key. (soporte.cfx.re)
  • Ports already in use: sudo ss -lntup | grep 30120; stop conflicting service or change FXSERVER_PORT.
  • Can’t reach txAdmin: Abierto 40120/TCP or change port; confirm NO_DEFAULT_CONFIG=1. (Documentación de Cfx.re)
  • Container exits on start: Asegurar tty: true y stdin_open: true are set. (GitHub)
  • Time/DNS issues: Ensure host time sync (systemd-timesyncd/chrony) and working DNS (/etc/resolv.conf).
  • SELinux denials (non-Ubuntu): Usar :Z/:z on bind mounts or adjust contexts.
  • info.json/players.json blocked: Some convars or proxies can affect these endpoints; confirm server responds on GET /info.json. (Documentación de Cfx.re)

Consejos de rendimiento

  • CPU/Memory: Pin CPUs and set memory limits (see extended compose).
  • Almacenamiento: Use SSD/NVMe; keep resource packs optimized; avoid huge, uncompressed assets.
  • Networking: Keep latency low; ensure host isn’t CPU throttled; prioritize UDP 30120.
  • Host kernel: Reasonable defaults work; advanced sysctls (net.core.*mem_max) can be tuned if you know your workload.
  • Registros: Use log rotation (as in extended example).

macOS / Windows notes

  • macOS (Docker Desktop): Bind-mounted file I/O is slower than native Linux; consider Docker Desktop’s Synchronized file shares for better performance and ensure the folder is shared in settings. (Documentación de Docker)
  • Windows (WSL2): Published ports are reachable via host local on Windows; exposing to LAN can require extra configuration depending on mode. Prefer hosting on Linux for public servers. (Documentación de Docker)

Clean Uninstall

# Stop and remove the container (keep data)
docker compose down

# Remove container + anonymous networks + images (keeps bind-mounted data)
docker compose down --rmi local --remove-orphans

# If you used named volumes (not in this guide), list and remove explicitly:
# docker volume ls
# docker volume rm <volume_name>

To delete todo data, remove the bind-mounted directories:

sudo rm -rf /home/fivem/data /home/fivem/txData

Preguntas frecuentes

Can I host multiple servers on one host?
Yes. Use separate project directories, different FXSERVER_PORT/TXADMIN_PORT, and distinct bind mounts. txAdmin supports per-profile data in /txData. (Documentación de Cfx.re)

How do I change the server name/IP shown in the list?
Editar sv_nombre de host en data/server.cfg. The IP/port comes from your published ports and NAT config.

Can I restart automatically on crash?
Sí. restart: unless-stopped in Compose; also consider systemd timers for watchdogs.

Where are backups located?
Where you create them—e.g., fivem-backup_YYYY-MM-DD.tgz in your working directory. See the backup commands above.

How do I enable txAdmin?
Colocar NO_DEFAULT_CONFIG=1, bind-mount /txData, and open 40120/TCP. (GitHub)

Do I need 30110 open?
Rarely. It was used for legacy listing; modern setups typically only need 30120 and txAdmin’s 40120 if used. (Comunidad Cfx.re)

How do I move the server to another machine?
Copiar datos/ y txData/ to the new host, recreate the same Compose file, and start.



Lucas
Lucas

Soy Luke, gamer y me encanta escribir sobre FiveM, GTA y juegos de rol. Dirijo una comunidad de juegos de rol y tengo unos 10 años de experiencia administrando servidores.

Artículos: 436