This article aims to show how you can host your own Minecraft server running in a Docker container in around 2 minutes. The starting point is a working Ubuntu server, but because we’re using Docker, it could be any system that allows you to run Docker containers. I’m using Ubuntu, which impacts the packages to install and directory locations.
Install Docker:
apt update apt install docker docker-compose docker.io
Prepare the directory structure:
mkdir /opt/minecraft mkdir /opt/minecraft/data cd /opt/minecraft
Prepare the Docker compose file “/opt/minecraft/docker-compose.yml” with the following content:
services:
mc:
image: itzg/minecraft-server
tty: true
stdin_open: true
ports:
- "25565:25565"
environment:
EULA: "TRUE"
TYPE: FORGE
OPS: "alice"
ENFORCE_WHITELIST: "TRUE"
WHITELIST: |
alice
ben
volumes:
- ./data:/data
restart: always
Note: The EULA line in the above means that you are accepting the end user agreement.
Specifying the admin user. This line is a comma separated list of admin users. Remove this line if you don’t want anyone with this power.
OP: "alice"
To Whitelist or not to Whitelist. The above example includes an whitelist option. It simply means that only these usernames are accepted into the game server. Remove these lines to allow anyone in.
ENFORCE_WHITELIST: "TRUE"
WHITELIST: |
alice
ben
Start the container:
docker-compose up -d
To stop your Docker container – without losing anything because the data is stored on the system in the “./data” location:
docker-compose down
The Docker container will auto start when Docker (the service) starts.
The default port to listen on is “tcp/25565”. If you want to allow those outside of your network to access your Minecraft server, you may need to port forward that port from the router to the Minecraft server.
The “server.properties” file lives in the “./data” directory. Any changes to that file requires you to bring the Docker container down and then back up again – using the commands above.
The following is a good resource: https://ruan.dev/blog/2024/11/10/run-a-minecraft-server-with-docker-compose