Docker-compose, Caddy & Minecraft (papermc)

Docker-compose, Caddy & Minecraft (papermc)

Here is how I setup Docker with Caddy and PaperMC (bukkit version of Minecraft). Now I have a pretty beefy home machine and use it to host a lot of different web apps including this blog.

OS: EndeavourOS x86_64
Kernel: Linux 6.11.5-arch1-1
CPU: 12th Gen Intel(R) Core(TM) i5-12400F (12) @ 4.40 GHz
GPU: AMD Radeon RX 6700 [Discrete]
Memory: 19.98 GiB / 62.61 GiB (32%)

Let's start with Docker Compose file

docker-compose.yml

x-logging: &default-logging
  options:
    max-size: "500m"
  driver: json-file
networks:
  web:
    external: true
  caddy_internal:
    external: false
    driver: bridge
services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    container_name: caddy
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./data/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./data/caddy/data:/data # Optional
      - ./data/caddy/config:/config # Optional
      - ./data/caddylog:/var/log/caddy
    networks:
      - web
      - caddy_internal
papermc:
    image: itzg/minecraft-server
    container_name: papermc
    environment:
      PUID: 1000
      PGID: 1000
      EULA: "true"
      TYPE: PAPER
      VERSION: 1.21.1
      VIEW_DISTANCE: 10
      JVM_OPTS: "-Xms8G -Xmx8G"
      JVM_XX_OPTS: "-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1"
      JVM_DD_OPTS: "-Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true"
    networks:
      - web
      - caddy_internal
    ports:
      - "25565:25565"
      - "12345:12345"
      - "8100:8100"
    volumes:
      - "./data/papermc:/data"
    restart: unless-stopped

This will create a docker containers caddy and papermc. Let's create some directories.

mkdir -p data/caddy
mkdir -p data/papermc
mkdir data/papermc/plugins

Next lets create the Caddyfile in ./data/caddy directory. Here we setup logging the access log for analytics. Won't cover setting that up here but if you need to do local analytic analysis with something like goaccess, this is the file it will use.

Also I am setting up two subdomains.

{
  email someemail@somewhere.intheworld
}
(logging) {
  log {
    output file /var/log/caddy/access.log
  }
}
mc.mydomain.club {
  reverse_proxy papermc:25565
}

map.mydomain.club {
  reverse_proxy papermc:8100
}

The mc.mydomain.club will be the server you would type in to join in minecraft client. map.mydomain.club will point to using the papermc plugin bluemap. Blue map generates nice map of your world you can view online.

Minecraft world rendered via Bluemap plugin and generated using Chunky plugin

Next setup your DNS A records for mydomain.club, I use Cloudflare to manage my DNS records but any service managing your domain can handle DNS changes.

TYPE    NAME    CONTENT                 PROXY
A       map     <my router ip address>  DNS Only
A       mc      <my router ip address>  DNS Only

I then forward port 443 and 80 to my machine from my home router. Caddy will pick that up and generate SSL certs from Let's Encrypt for my URLs.

Let's try and setup some files for Minecraft. First we need to download Bluemap

cp ~/Downloads/bluemap*.jar data/papermc/plugins

Let's startup the containers!

sudo docker-compose up -d

If all is well they should be started

docker ps

The data/papermc directory should have all the config files now and we need to update the config file for bluemap and change one setting. Edit data/papermc/plugins/BlueMap/core.conf and update the this property to true accept-download: true

Recycle docker and you should be able to play on your own multi-player minecraft server and see a map of your world!

sudo docker-compose down
sudo docker-compose up -d

Other plugins I like to use with papermc are: