Minecraft Bedrock Server

Minecraft is a popular sandbox video game that allows players to build and explore virtual worlds made of blocks. While many players enjoy the official Minecraft Realms service, self-hosting your own Minecraft Bedrock server gives you complete control over your gaming environment, including custom settings, mods, and the ability to play with friends without ongoing subscription costs. The itzg/minecraft-bedrock-server Docker image makes it incredibly simple to deploy and manage your own Minecraft Bedrock Edition server.

The Docker Compose File

---
services:
  minecraft-bedrock:
    image: itzg/minecraft-bedrock-server:latest
    container_name: minecraft-bedrock
    restart: unless-stopped
    environment:
      EULA: "TRUE"
      SERVER_NAME: "My Bedrock Server"
      GAMEMODE: "survival"
      DIFFICULTY: "normal"
      ALLOW_CHEATS: "false"
      MAX_PLAYERS: "10"
      ONLINE_MODE: "true"
      WHITE_LIST: "false"
    ports:
      - "19132:19132/udp"
    volumes:
      - ./data:/data
    stdin_open: true
    tty: true

This Docker Compose file defines a single service named 'minecraft-bedrock'. The service is built from the 'itzg/minecraft-bedrock-server:latest' Docker image, which is maintained by the community and provides an easy way to run Minecraft Bedrock Edition servers in containers.

The 'restart' policy is set to 'unless-stopped', which ensures that the container will automatically restart if it crashes or if the Docker daemon restarts, but won't restart if you manually stop it. This is particularly useful for game servers that need high availability, as it means your Minecraft server will come back online automatically after unexpected shutdowns or system reboots.

The 'environment' section contains several important configuration options for your Minecraft server. The 'EULA' variable must be set to "TRUE" to accept Minecraft's End User License Agreement, which is required to run any Minecraft server. The 'SERVER_NAME' variable sets the name that will appear in the server list when players browse for games. The 'GAMEMODE' variable determines whether players start in survival, creative, or adventure mode, while 'DIFFICULTY' sets how challenging the game will be with options like peaceful, easy, normal, or hard.

The 'ALLOW_CHEATS' setting controls whether server operators can use command console cheats, and 'MAX_PLAYERS' limits how many people can connect to your server simultaneously. The 'ONLINE_MODE' variable enables Xbox Live authentication, which helps prevent unauthorized players from joining, and 'WHITE_LIST' determines whether only pre-approved players can connect. When set to "false", anyone who knows your server address can join.

The 'ports' section maps port 19132 on your host machine to port 19132 in the container using the UDP protocol. Minecraft Bedrock Edition specifically uses UDP rather than TCP, so this distinction is important. This port mapping allows Minecraft clients on your network (or the internet, if you configure port forwarding) to connect to your server.

The 'volumes' section maps the '/data' directory inside the container to a local './data' directory on your host machine. This is crucial because it stores your Minecraft world data, player inventories, server configuration files, and any other persistent data. Without this volume mapping, you would lose your entire Minecraft world every time you restart or update the container.

The 'stdin_open' and 'tty' settings enable interactive console access to the Minecraft server. This allows you to attach to the running container and execute server commands directly, which is useful for administrative tasks like banning players, changing the time of day, or teleporting players.

Additional Configuration

Before starting your server, you may want to customize the environment variables to match your preferences. If you plan to run a private server for friends, consider enabling the whitelist by setting 'WHITE_LIST' to "true". You'll then need to add player Xbox gamertags to the whitelist by connecting to the server console after it starts.

For servers that will be accessible from the internet, make sure to configure your router's port forwarding to direct UDP traffic on port 19132 to your Docker host machine. Additionally, consider the security implications of running a public server and whether you want to enable online mode to require Xbox Live authentication.

Running Minecraft Bedrock Server with Docker Compose

To run your Minecraft Bedrock server with Docker Compose, first make sure you have Docker and Docker Compose installed on your machine. Then, create a new directory for your project and save the above Docker Compose file as 'docker-compose.yml' in that directory.

Next, run the following command from the same directory:

docker compose up -d

This command will start the Minecraft Bedrock container in the background and detach from it. The first startup may take a minute or two as the server generates the initial world and configuration files. You can monitor the startup progress by checking the logs with 'docker compose logs -f minecraft-bedrock'.

Once the server is running, you can connect to it from Minecraft Bedrock Edition on any device by adding a new server with your host machine's IP address and port 19132. If you're connecting from the same machine running the server, you can use 'localhost' as the server address. To access the server console for administrative commands, use 'docker attach minecraft-bedrock', and press Ctrl+P followed by Ctrl+Q to detach without stopping the server.

Conclusion

In this article, we explored how to set up and run a Minecraft Bedrock Edition server using Docker Compose. We looked at the different sections of the Docker Compose file and explained how they work together to create a functional game server with persistent world storage and configurable gameplay options. By running Minecraft Bedrock server with Docker Compose, you can easily host multiplayer gaming sessions for your friends and family without having to worry about complex server installations or ongoing subscription fees.