Minecraft, Docker-Compose, Console Commands

I run a few Minecraft servers for my kids using docker-compose and the excellent itzg docker images.

Sometimes they request I tweak the game rules and I need to connect to the console of a running server.

Make sure the container you are trying to connect to has the following docker-compose options:

1
2
stdin_open: true
tty: true

The java Minecraft server service in my docker-compose currently looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
minecraft-java:
image: itzg/minecraft-server
stdin_open: true
tty: true
environment:
EULA: "TRUE"
MODE: survival
SEED: "REDACTED"
SERVER_NAME: REDACTED
DIFFICULTY: hard
MEMORY: 4G
ports:
- 25565:25565
volumes:
- /media/gamedata/minecraft-java:/data
restart: unless-stopped

Start up the servers and run docker container ls to find out the final name docker-compose assigned to the container. Mine was minecraft_minecraft-java_1.

Now run docker attach minecraft_minecraft-java_1 and you will be in console mode and able to run gamerule commands etc.