DEV Community

Celso Nery
Celso Nery

Posted on

Minecraft Server - Part 2: Running with Docker

🇧🇷 Versão em português

Minecraft Server - Part 2: Running with Docker

In Part 1 of this series, we installed the Minecraft server (Bedrock and Java) directly on the operating system, manually managing the process with screen/tmux. In this article, we take a natural next step: running the same server in a Docker container, using the community-maintained images from itzg/docker-minecraft-server and itzg/docker-minecraft-bedrock-server.

Advantages over the bare metal installation:

  • Automatic restart on failure (restart: unless-stopped);
  • Isolated and explicit data persistence, via volumes;
  • Declarative configuration, in a single versionable file;
  • Isolation of the process from the rest of the system.

Prerequisite: Docker and Docker Compose must already be installed. If you haven't installed them yet, please do so. If you're not sure how, check out my "Docker for Developers" series; in Part 1, I show how to install Docker.

Running Minecraft Bedrock with Docker

version: "3.8"

services:
  minecraft-bedrock:
    image: itzg/minecraft-bedrock-server:latest
    container_name: minecraft-bedrock-server
    restart: unless-stopped
    ports:
      - "19132:19132/udp"
    environment:
      EULA: "TRUE"
      GAMEMODE: "survival"
      MAX_PLAYERS: "10"
      MOTD: "Bedrock Minecraft Server!"
      WHITELIST: "false"
      OPS: "your_username"
    volumes:
      - minecraft-bedrock-data:/data

volumes:
  minecraft-bedrock-data:
    driver: local
Enter fullscreen mode Exit fullscreen mode

Important points:

  • ports: "19132:19132/udp": Bedrock uses UDP, unlike most network services, notice the explicit /udp suffix;
  • EULA: "TRUE": automatically accepts the Minecraft license, skipping the manual eula.txt step seen in Part 1;
  • OPS: already grants operator permission to the given user on first startup;
  • minecraft-bedrock-data: a named volume, ensuring the world and settings survive container updates and recreations.

Running Minecraft Java with Docker

version: "3.8"

services:
  minecraft-java:
    image: itzg/minecraft-server:latest
    container_name: minecraft-java-server
    restart: unless-stopped
    ports:
      - "25565:25565"
    environment:
      EULA: "TRUE"
      GAMEMODE: "survival"
      MAX_PLAYERS: "10"
      MOTD: "Java Minecraft Server!"
      WHITELIST: "false"
      OPS: "your_username"
    volumes:
      - minecraft-java-data:/data

volumes:
  minecraft-java-data:
    driver: local
Enter fullscreen mode Exit fullscreen mode

Important: unlike Bedrock, Minecraft Java uses TCP, not UDP, the port should be mapped as "25565:25565" (TCP is Docker's default protocol when none is specified), without the /udp suffix.

Bringing up the servers

Each server can live in its own docker-compose.yaml file (recommended, so you can manage them independently) or both in the same file, as two separate services.

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Following the startup logs (the first start can take a few minutes, downloading the server files):

docker compose logs -f
Enter fullscreen mode Exit fullscreen mode

Managing the server via console

The itzg images include a built-in RCON tool (rcon-cli) inside the container, letting you run server commands without needing to attach directly to the process:

docker exec -it minecraft-java-server rcon-cli
Enter fullscreen mode Exit fullscreen mode

Inside the RCON console, the same commands from Part 1 work normally:

whitelist add new_player
op new_player
Enter fullscreen mode Exit fullscreen mode

For Bedrock, the container also accepts commands via send-command (depending on the image version) or directly through the WHITELIST and OPS environment variables in docker-compose.yaml, restarting the container to apply changes.

The itzg images have a large number of available environment variables (difficulty, world type, plugins, mods, etc.), it's worth checking each image's official documentation on Docker Hub for the complete, up-to-date list, since new options are added frequently.

Docker Hub itzg repository

Next steps

With Minecraft running in Docker containers, we now have automatic restart, persistence, and declarative configuration. But this still runs on a single host, if the machine goes down, the server goes down with it. In Part 3 of this series, we'll take the same server into a Kubernetes cluster, gaining features like managed storage via PersistentVolumeClaim and the ability to run on any available node in the cluster.

Continued in Part 3.

Top comments (0)