Setting Up a Minecraft Server with Docker
Introduction:
Minecraft is a popular sandbox video game, and with Docker, you can easily create and manage a Minecraft server. Docker allows you to encapsulate the server environment, making it easy to deploy and maintain. In this guide, we’ll show you how to set up a Minecraft server using Docker and configure its settings.
Step 1: Install Docker
Before proceeding, ensure you have Docker installed on your system. If you haven’t installed Docker yet, follow the official Docker installation instructions for your operating system.
Step 2: Pull the Minecraft Server Docker Image
To run the Minecraft server, pull the latest Minecraft Server Docker image from Docker Hub using the following command:
docker pull itzg/minecraft-server:latest
Step 3: Create and Start the Minecraft Server Container
Run the following command to create and start the Minecraft server container:
docker run -d -it --name minecraft -v minecraft_data:/data -p 25565:25565 -e EULA=TRUE -e MODE=creative -e MEMORY=2G -e tty=true --restart always itzg/minecraft-server:latest
Explanation of options used:
-d
: Run the container in the background (detached mode).-it
: Allocate a pseudo-TTY and keep STDIN open, allowing you to interact with the server console.--name minecraft
: Assign the name “minecraft” to the container for easy management.-v minecraft_data:/data
: Create a Docker volume named “minecraft_data” and mount it to the/data
directory inside the container. This volume allows you to persist Minecraft world data and configurations.-p 25565:25565
: Map port 25565 from the container to the host system. This is the default port for Minecraft servers.-e EULA=TRUE
: Accept the Minecraft End User License Agreement (EULA).-e MODE=creative
: Set the server mode to “creative.” You can change this to “survival” or other valid game modes.-e MEMORY=2G
: Set the allocated memory for the server to 2GB. Adjust this value based on your server’s requirements.-e tty=true
: Enable the TTY (Terminal) for interacting with the server console.--restart always
: Configure the container to automatically restart if it stops unexpectedly.
Step 4: Access the Minecraft Server Console
To access the Minecraft server console interactively, use the following command:
docker attach minecraft
This command will attach your current terminal to the running Minecraft server container, providing you with an interactive console to manage the server.
Step 5: Clean Up
If you want to stop and remove the Minecraft server container and the associated volume, use the following commands:
docker stop minecraft
docker rm minecraft
docker volume rm minecraft_data
Conclusion:
You’ve successfully set up a Minecraft server using Docker, allowing you to host and manage your Minecraft world easily. Docker’s portability and isolation make it a convenient choice for running a Minecraft server without interfering with your host system. Enjoy playing and exploring your Minecraft creations!
Happy mining!