Skip to content

Instantly share code, notes, and snippets.

@xane256
Last active February 2, 2024 23:18
Show Gist options
  • Save xane256/0f1e4985158df7ee593e4c783d05e96e to your computer and use it in GitHub Desktop.
Save xane256/0f1e4985158df7ee593e4c783d05e96e to your computer and use it in GitHub Desktop.
minecraft-docker-compose

Project file structure

files and folders:

  • docker-compose.yml: main file
  • env/container.env: common settings for most servers
  • env/cmp.env: settings for cmp server
  • mods/1.20.1/base: folder of jar file mods for all servers
  • mods/1.20.1/creative: folder of jar file mods for creative server only
  • servers/cmp: folder for all server data for cmp server

File tree in VS Code

You can run this shell script / copy-paste to terminal to create the files & folders:

mkdir -p env servers/cmp mods/1.20.1/base mods/1.20.1/creative
touch docker-compose.yml env/container.env env/cmp.env

docker-compose.yml

version: "3.7"
services:
  cmp:
    image: itzg/minecraft-server:latest
    stdin_open: TRUE
    tty: TRUE
    stop_grace_period: 15s
    restart: on-failure
    container_name: "cmp"
    ports: ["25565:25565"]
    env_file:
      # Multiple files are allowed.
      # Variables set in multiple files get the value from the last file.
      # The files are processed in order so new assignments overwrite old ones.
      - "./env/container.env"
      - "./env/cmp.env"
    environment: # These values overwrite those from env files
      EULA: TRUE
      VERSION: 1.20.1
      TYPE: "FABRIC"
      LEVEL: "world"
      MOTD: §3Docker Minecraft Server
      # `MODS` copies jar files from multiple folders to the `/data/mods` folder in the container on every startup
      MODS: "/modfiles/base,/modfiles/creative"
      REMOVE_OLD_MODS: "TRUE"
      OVERRIDE_SERVER_PROPERTIES: "TRUE"
      # Optional UID / GID.
      # Uncomment & set these if you get errors about read/write permissions for mounted files
      # UID: 1000 # replace with the value of `id -u` from your shell
      # GID: 1000 # replace with the value of `id -g` from your shell
    volumes:
      - "./servers/cmp:/data"
      - "./mods/1.20.1:/modfiles:ro"

env-file container.env

### Filesystem and JVM
INIT_MEMORY=1G
MAX_MEMORY=4G
# This setting uses a pre-defined set of JVM flags optimized for minecraft.
USE_AIKAR_FLAGS=TRUE

### Docker Image
EULA=TRUE
TYPE=FABRIC

### Container Settings
TZ=America/Los_Angeles
# Autopause when no players are online.
# This pauses the java process and saves resources, and doesn't interfere with chunk-loading within the game
ENABLE_AUTOPAUSE=TRUE
MAX_TICK_TIME=-1
autoheal=FALSE
RCON=TRUE
RCON_PASSWORD=mc

### Whitelist
# https://docker-minecraft-server.readthedocs.io/en/latest/configuration/server-properties/#whitelist-players
ENFORCE_WHITELIST=TRUE
ENABLE_WHITELIST=TRUE

env-file cmp.env

# server.properties
ONLINE_MODE=TRUE
OP_PERMISSION_LEVEL=2
ENFORCE_SECURE_PROFILE=FALSE

# game settings
MODE=CREATIVE
DIFFICULTY=hard
SPAWN_ANIMALS=TRUE
SPAWN_MONSTERS=FALSE
SPAWN_NPCS=TRUE
SPAWN_PROTECTION=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment