Running a Minecraft server to play with friends can be a rewarding experience. However, setting it up traditionally can be complex and time-consuming. Docker simplifies this process, allowing you to get your Minecraft server up and running quickly and efficiently. This guide will walk you through how to easily set up a Docker Minecraft Server using the popular itzg/minecraft-server
image.
To get started with the latest stable version of Minecraft Server, simply use the following Docker command:
docker run -d -it -p 25565:25565 -e EULA=TRUE itzg/minecraft-server
This single line of code is all it takes to launch your Minecraft server! Let’s break down what this command does:
docker run
: This is the Docker command to run a new container.-d
: Runs the container in detached mode, meaning it runs in the background.-it
: Allocates a pseudo-TTY connected to the container and keeps STDIN open even if not attached.-p 25565:25565
: Maps port 25565 on your host machine to port 25565 in the container. This is the standard port for Minecraft servers, allowing players to connect.-e EULA=TRUE
: Crucially, this sets the environment variableEULA
toTRUE
, indicating that you agree to the Minecraft End User License Agreement. You must include this to legally run a Minecraft server.itzg/minecraft-server
: This specifies the Docker image to use.itzg/minecraft-server
is a well-maintained and popular Docker image specifically designed for running Minecraft servers.
After running this command, your Minecraft server will start downloading the latest stable Minecraft server version and become accessible on port 25565 of your host machine’s IP address.
This is a Docker Pulls badge showcasing the popularity and usage of the itzg/minecraft-server Docker image.
Managing Your Minecraft Server with Docker Compose
While the docker run
command is perfect for a quick start, for long-term server management and easier configuration, Docker Compose is highly recommended. Docker Compose allows you to define and manage multi-container Docker applications. In our case, it simplifies managing your Minecraft server container and its settings.
Here’s how to set up your Minecraft server with Docker Compose:
- Create a Directory: Make a new directory on your host machine where your Docker Compose file and server data will reside. For example, you can name it
minecraft-docker-server
. - Create
docker-compose.yml
: Inside this directory, create a file nameddocker-compose.yml
. This file will define your Minecraft server service. - Paste the following configuration into
docker-compose.yml
:
services:
mc:
image: itzg/minecraft-server
tty: true
stdin_open: true
ports:
- "25565:25565"
environment:
EULA: "TRUE"
volumes:
- ./data:/data
Let’s break down this docker-compose.yml
file:
services:
: Defines the services that make up your application. In this case, we have one service calledmc
(short for Minecraft).image: itzg/minecraft-server
: Specifies the Docker image to use, just like in thedocker run
command.tty: true
andstdin_open: true
: These options are useful for interacting with the server console if needed.ports:
: Defines port mappings, again mapping host port 25565 to container port 25565.environment:
: Sets environment variables for the container, includingEULA: "TRUE"
.volumes:
: This is crucial for data persistence.- ./data:/data
mounts a directory nameddata
(relative to thedocker-compose.yml
file) on your host machine to the/data
directory inside the container. This means your Minecraft server world, configurations, and logs will be stored in the./data
directory on your host and will persist even if you stop or remove the container.
This image is a representation of a Docker Compose configuration file, similar to the YAML example provided, for setting up a Minecraft server.
-
Run Docker Compose: In the same directory as your
docker-compose.yml
file, run the command:docker compose up -d
This command will start your Minecraft server in detached mode using the configuration defined in
docker-compose.yml
. -
Manage Your Server: You can now manage your server using Docker Compose commands:
docker compose logs -f
: Follow the logs of your Minecraft server container.docker compose ps
: Check the status of your container.docker compose stop
: Stop your Minecraft server.docker compose down
: Stop and remove the container.docker compose up -d
: Restart the server and apply any changes made todocker-compose.yml
.
Explore Further Configuration and Versions
The itzg/minecraft-server
image is highly configurable. You can easily change the Minecraft version, server type (Vanilla, Spigot, Paper, etc.), and many other settings using environment variables. To explore the full range of customization options, refer to the official documentation for the itzg/minecraft-server
Docker image.
Running a Minecraft server in Docker offers a streamlined and efficient way to host your own game server. Whether you choose the simple docker run
command for a quick setup or Docker Compose for robust management, you’ll find it significantly easier than traditional server setup methods. Enjoy building and playing in your own Dockerized Minecraft world!