Docker: Use Docker Compose for Minecraft
I'll show you how to use Docker Compose to run a Minecraft server

My son has been a big Minecraft fan for many years. He plays it on the PC, Nintendo Switch, and also on my MS Xbox.
But one day, he told me that he and his friends wanted to have an own server - "and it will not cost very much, just a few € a month" 😑
But why should I spend money on something I could have for free? My server in the Oracle cloud has enough resources for that. So just give it a try. Here's my docker-compose.yml
:
services:
mc:
image: itzg/minecraft-server
hostname: minecraft
environment:
EULA: "true"
SERVER_NAME: "NameOfMyMinecraftServer"
MOTD: "A §l§cMinecraft§r §nserver"
MODE: creative
VERSION: 1.21.5
ports:
- "25565:25565"
volumes:
- data:/data
stdin_open: true
tty: true
restart: unless-stopped
Some explanations:
- the meaning of image and hostname should be clear
- Environment:
EULA
is mandatory - setting it totrue
means you accept the user agreement.SERVER_NAME
is the name of your server, as it's shown when you log inMODE
means the game mode. The possible modes are:- creative
- survival
- adventure
- spectator
VERSION
: Normally, I prefer the latest version. But sometimes, you would prefer a special version, for example if your son has a mod, like for a specific gamepadDIFFICULTY
sets how difficult the gameplay will beOPS
: this is the name of the admin user (in my case it was my son)
ports
: port 25565 is needed to connect the client to the server.TCP
andUDP
is needed!
Let's pull and start the container:
# docker compose pull
# docker compose up -d
✔ Container docker-minecraft-server-mc-1 Started 0.4s
Let's have a look at the log file:
# docker compose logs -f
mc-1 | [08:59:19] [ServerMain/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD]
mc-1 | [08:59:23] [ServerMain/INFO]: Loaded 1373 recipes
mc-1 | [08:59:23] [ServerMain/INFO]: Loaded 1484 advancements
mc-1 | [08:59:23] [Server thread/INFO]: Starting minecraft server version 1.21.5
mc-1 | [08:59:23] [Server thread/INFO]: Loading properties
mc-1 | [08:59:23] [Server thread/INFO]: Default game type: CREATIVE
mc-1 | [08:59:23] [Server thread/INFO]: Generating keypair
mc-1 | [08:59:24] [Server thread/INFO]: Starting Minecraft server on *:25565
mc-1 | [08:59:24] [Server thread/INFO]: Using epoll channel type
mc-1 | [08:59:24] [Server thread/INFO]: Preparing level "world"
mc-1 | [08:59:26] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 0%
mc-1 | [08:59:29] [Worker-Main-2/INFO]: Preparing spawn area: 51%
mc-1 | [08:59:29] [Server thread/INFO]: Time elapsed: 3607 ms
mc-1 | [08:59:29] [Server thread/INFO]: Done (5.414s)! For help, type "help"
mc-1 | [08:59:29] [Server thread/INFO]: Starting remote control listener
mc-1 | [08:59:29] [Server thread/INFO]: Thread RCON Listener started
mc-1 | [08:59:29] [Server thread/INFO]: RCON running on 0.0.0.0:25575
If your Docker server is running in your home network, clients can now connect to it:


If you're planning to make it available all over the internet, you'll have to change your router and open the ports. But keep in mind that this could be a security risk!