How to Set Up a Minecraft Server with Docker on Ubuntu
How to Set Up a Minecraft Server with Docker on Ubuntu
Setting up a Minecraft server can be an exciting project for gaming enthusiasts who want to create their own gaming space. Utilizing Docker to set up your server on Ubuntu simplifies the process, allowing for efficient resource management and easy updates. In this guide, we’ll walk through the steps required to get a Minecraft server running on your Ubuntu machine using Docker.
Prerequisites
Before you begin, ensure you have the following:
- Ubuntu Server: This guide is based on Ubuntu 20.04 or later.
- Docker: You need Docker installed on your system. If you haven’t installed Docker yet, you can do so by following these steps:
Update your package index:
sudo apt update
Install the required packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
Add the Docker repository:
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
Install Docker:
sudo apt update
sudo apt install docker-ce
Docker Compose: This tool is essential for managing multi-container Docker applications. Install it with:
sudo apt install docker-compose
Basic knowledge of Docker: Familiarity with basic Docker commands will be helpful, but you don’t need to be an expert.
Step 1: Create a Directory for Your Minecraft Server
It’s a good practice to keep your server files organized. Create a directory where your Minecraft server files will reside:
mkdir ~/minecraft-server
cd ~/minecraft-server
Step 2: Create a Docker Compose File
Now, you’ll create a Docker Compose file that defines the Minecraft server configuration. Create a file named docker-compose.yml:
nano docker-compose.yml
Add the following configuration to the file:
version: ‘3.8’
services:
minecraft:
image: itzg/minecraft-server
ports:
– “25565:25565” # Minecraft default port
environment:
EULA: “TRUE” # Accept Minecraft EULA
VERSION: “LATEST” # Specify the version you want to run
MAX_PLAYERS: 20 # Maximum players allowed
volumes:
– minecraft_data:/data # Volume for persistent data
restart: unless-stopped # Automatically restart the server if it stopsvolumes:
minecraft_data:
Explanation of Configuration:
- image: This specifies the Docker image to use. The itzg/minecraft-server image is a widely-used community image that makes it easy to set up Minecraft servers.
- ports: This maps the default Minecraft port from the container to the host.
- environment: Here, we set the environment variables, including accepting the EULA, specifying the version, and limiting the maximum number of players.
- volumes: This creates a volume for persistent storage of server data, ensuring that your world and configurations are saved even if the container is stopped.
- restart: This directive ensures that the server container restarts automatically unless manually stopped.
Step 3: Launch the Minecraft Server
With your docker-compose.yml file ready, you can now launch the Minecraft server using Docker Compose. In your terminal, run:
docker-compose up -d
The -d flag runs the container in detached mode, allowing it to run in the background. You should see output indicating that the server is starting up.
Step 4: Access the Server
To join your newly created Minecraft server, open your Minecraft client, select “Multiplayer,” then “Add Server.” Enter your server’s IP address (if you are playing on the same machine, use localhost) and port 25565. Click “Done,” and you should see your server listed. Click on it to join.
Step 5: Managing the Server
Stopping the Server
To stop your Minecraft server, use the following command:
docker-compose down
This command will gracefully stop and remove the container.
Updating the Server
To update your Minecraft server to the latest version, you can pull the latest image and recreate the container:
docker-compose pull
docker-compose up -d
Accessing the Server Console
To access the console of your Minecraft server, run:
docker-compose exec minecraft bash
From there, you can issue commands as you would in the regular Minecraft server console.
For more information, you can check the official Docker documentation and the Minecraft server image documentation.
Thank you for visiting our page! Be sure to explore our other article via the link below to boost your Linux expertise. Also, don’t miss our guide on How to Use Fail2Ban to Block Brute Force Attacks on Ubuntu! 🙂