Setting Up a Minecraft Server Using Docker (Step by Step)
Setting up a Minecraft server using Docker offers a robust and streamlined approach, addressing common complexities associated with traditional server hosting. Docker containers provide an isolated environment for the Minecraft server, effectively preventing conflicts that might arise with other applications or different Java versions on the host system. This isolation ensures a stable and predictable operating environment for your game server.
![]()
The foundation of this setup relies on the itzg/minecraft-server Docker image, a widely recognized and well-maintained solution. This versatile image supports a comprehensive range of server types, including Vanilla, Forge, Fabric, Paper, and Spigot, catering to diverse player preferences and modding requirements. Docker itself facilitates easy management, including straightforward updates and reliable backup procedures for your server.
Crucial for any server is data persistence, ensuring that your worlds, player data, and configurations are never lost. This is achieved through Docker volumes, which map a specific directory on your host machine to the container’s /data directory. Server configurations, such as the mandatory End User License Agreement (EULA) acceptance, selection of server type, specific game version, and memory allocation, are efficiently managed via environment variables, centralizing control over your server’s parameters.
Step-by-step process
-
Prerequisites:
Ensure that both Docker Engine and Docker Compose are installed on your machine. Docker Engine is responsible for running containers, while Docker Compose simplifies the definition and management of multi-container applications through a single configuration file.
-
Create a Project Directory:
Establish a new, dedicated directory on your host machine. This directory will house your
docker-compose.ymlfile and serve as the location for your server’s persistent data. -
Define with Docker Compose (Recommended):
Inside your project directory, create a file named
docker-compose.yml. This file will outline the entire configuration for your Minecraft server container.-
Specify the
itzg/minecraft-serverimage: Declare the use of theitzg/minecraft-serverDocker image for your service. -
Map the default Minecraft port (25565): Expose port 25565 from the container to the host, allowing external connections to your server (e.g.,
"25565:25565"). -
Set environment variables: Crucially, set
EULA=TRUEto accept the Minecraft End User License Agreement. Without this, the server will not start. Additionally, you can configure other settings likeTYPE(e.g.,PAPER),VERSION(e.g.,1.20.1),MEMORY(e.g.,4G), andMOTDvia environment variables. -
Define a volume for data persistence: Create a Docker volume to map a directory on your host (e.g.,
./data) to the container’s/datadirectory. This ensures that your world, player data, and configurations persist even if the container is removed or updated.
-
-
Start the Server:
Navigate to your project directory in the terminal. Execute
docker-compose up -d. This command will download the necessary image, create the container, and start your Minecraft server in detached mode, allowing it to run in the background. -
Connect:
Open your Minecraft client, go to “Multiplayer,” and “Add Server.” Enter the IP address or hostname of your Docker host machine, typically followed by port 25565. You should then be able to connect to your newly configured server.
Important Tips
-
Data Persistence:
Always utilize Docker volumes to safeguard your world data and configurations. Mapping a host directory to the container’s
/datadirectory ensures that your progress is preserved across container updates or recreations, preventing data loss. -
EULA Acceptance:
Accepting the Minecraft End User License Agreement is mandatory. Set the environment variable
EULA=TRUEin yourdocker-compose.ymlfile; otherwise, your server will fail to start. -
Resource Allocation:
Allocate sufficient RAM to your server. A minimum of 2GB is required, but 4GB is recommended for a comfortable experience, especially with multiple players or mods. Insufficient RAM can lead to significant lag and server instability.
-
Docker Compose:
Employing
docker-composeis highly recommended for its ability to provide a consistent, manageable, and easily reconfigurable setup. It centralizes your server’s entire configuration in a single file. -
Automated Backups:
Protect your server data by implementing automated backups. Consider using companion containers like
itzg/mc-backupto create regular snapshots, offering peace of mind and recovery options. -
Specific Versions:
Avoid using the
latesttag for the Docker image in production. Instead, specify a particular version (e.g.,itzg/minecraft-server:2023.10.1) to ensure reproducibility and prevent unexpected updates from causing instability or breaking changes. -
Aikar’s Flags:
For enhanced performance and reduced lag spikes, especially concerning Java’s memory management, enable Aikar’s Flags. These optimized JVM arguments significantly improve server stability and responsiveness, often configurable via an environment variable.
Common Mistakes to Avoid
-
Not Accepting the EULA:
Forgetting to set
EULA=TRUEis a common error that will prevent your server from launching, resulting in an immediate shutdown with an EULA non-acceptance message. -
Lack of Data Persistence:
Running a server without a mounted volume means all world data, player progress, and configurations will be permanently lost if the container is removed or recreated. Always ensure your volume mapping is correctly configured.
-
Port Conflicts:
If the default Minecraft port (25565) is already in use on your host machine, your server will fail to start correctly. Verify port availability or map to an alternative host port.
-
Firewall Issues:
External connections may be blocked by your host’s firewall or your router’s port forwarding settings. Ensure port 25565 is open in your firewall and correctly forwarded if behind a router, to allow players to connect.
-
Using
latesttag:Relying on the
latesttag for the Docker image can lead to unpredictable behavior and potential breaking changes after automatic updates. Always specify a fixed version for stability and control. -
Insufficient RAM:
Not allocating enough memory (e.g., less than 2GB, or less than 4GB for active servers) is a frequent cause of server lag, performance issues, and crashes. Adjust the
MEMORYenvironment variable to provide adequate resources.