Modded Minecraft in Docker
━━━━━━━━━━━━━━━━━━━━━━━━━━

In my adventure to put more homelab in docker, I moved our modded minecraft setup to docker.

Date: February 16, 2022

In my adventure to put more [4m[38;2;248;248;242mhomelab[0m <[38;2;248;248;242m/homelab/[0m> in docker, I moved our modded minecraft setup to docker.

[1m[38;2;189;147;249mGetting Mods[0m
[38;2;68;71;90m────────────[0m

So far I have found all of our mods from [4m[38;2;248;248;242mcurse forge[0m <[38;2;248;248;242mhttps://www.curseforge.com/minecraft/mc-mods[0m>. modpacks make getting multiple mods working together much easier, someone else has already vetted a pack of often times 100+ mods that all play well together. I have yet to get these working in docker, I will, but for not I just have individual mods.

[1m[38;2;189;147;249mdownload file[0m
[38;2;68;71;90m─────────────[0m

under the hood docker is using wget to get the mod. The link you click on from curseforge will block wget. What I do is pop open the devtools (f12 in chrome), click on the network tab, click the download link on the web page, and watch the real link show up.

Image: minecraft mod in netwrok tab <https://dropper.waylonwalker.com/file/cfe3359c-c8ba-454c-96ec-ef2be98f2a35.webp>

[1m[38;2;189;147;249mDocker-compose[0m
[38;2;68;71;90m──────────────[0m

I am using docker compose, it makes the command much easier to start, and all the things needed stored in a file. I am not using compose to run multiple things, just for the simple start command.

Create a directory for your server and add the following to a [38;2;189;147;249mdocker-compose.yml[0m file.

[38;2;248;248;242m[code][0m
  version: "3.8"

  services:
    mc:
      container_name: walkercraft
      image: itzg/minecraft-server
      ports:
        - 25565:25565
      environment:
        EULA: "TRUE"
        TYPE: "FORGE"
        VERSION: 1.16.5
        MODS_FILE: /extras/mods.txt
        REMOVE_OLD_MODS: "true"
      tty: true
      stdin_open: true
      restart: unless-stopped
      ports:
        - 25565:25565
      volumes:
        - ./minecraft-data:/data
        - ./mods.txt:/extras/mods.txt:ro

  volumes:
    data:

[1m[38;2;189;147;249mmods.txt[0m
[38;2;68;71;90m────────[0m

Once you have your mod file link from the network tab add them to a mods.txt file next to your docker-compose file.

[38;2;248;248;242m[code][0m
  https://media.forgecdn.net/files/3620/189/engineersdecor-1.16.5-1.1.16.jar

[1m[38;2;189;147;249mstart your server[0m
[38;2;68;71;90m─────────────────[0m

Once you have made it this far starting the server is pretty simple.

[38;2;248;248;242m[code][0m
  docker compose up -d

[1m[38;2;189;147;249mkill your server[0m
[38;2;68;71;90m────────────────[0m

If your still in the same directory, taking down the server should be pretty easy as well.

[38;2;248;248;242m[code][0m
  docker compose down

  # if that does not work you can kill it
  docker ps
  # copy the id of your container
  docker kill <id>
