[DOCKER] Build a container version of Minecraft server and use https-enabled Dynmap

Introduction

In this article, we will build a Minecraft server with a container. I think there are many ways to create a virtual machine, install the JDK, execute the jar file, and so on. There is no problem with this method, but I will introduce the container version Minecraft + α that can be made quickly. You can create the following server in this way.

Diagram kouseizu.png

** * Prerequisites **

Introduction of what to use

Introducing the container and MOD used this time. Since Forge will be introduced, it is okay to introduce various things other than Dynamap.

docker-letsencrypt-nginx-proxy-companion A container stack with Nginx-based reverse proxy function and Let's Encrypt certificate issuance function. It functions as a reverse proxy for the web server behind it while automatically issuing and renewing the certificate. Since the http-01 challenge is used to authenticate the certificate issuance, communication on the IN side TCP port 80,443 is required. https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion

itzg/minecraft-server A container version of Minecraft maintained by itzg (Geoff Bourne). If it is a vanilla server, just start this container and the Minecraft server will start up. https://github.com/itzg/docker-minecraft-server

Minecraft Forge Prerequisite mods when applying various mods to Minecraft. Most mods require this Forge. This time Dynamap also uses Forge (there are other versions besides Forge). http://files.minecraftforge.net

Dynmap It is a mod that allows you to check the world of Minecraft with a Google Map-like UI from a web browser. It is very highly functional, such as being able to check directly above, diagonally, and another dimension, setting various markers, and having a chat function. Furthermore, since it has a simple Web server from the beginning, it can be used without preparing a separate Web server. This time, we will access this simple web server via a reverse proxy. https://www.curseforge.com/minecraft/mc-mods/dynmapforge

Install docker-letsencrypt-nginx-proxy-companion

With this, Nginx's reverse proxy function and Let's Encrypt enable https conversion. For example, if you have your own domain, you can access Dynmap with an address like https \ //dynmap.yourdomain.com/. Since it is a convenient Docker stack that can be used other than Minecraft, this time I will make the docker-compose file independent. Start the containers with docker-compose.yml below.

docker-compose.yml


version: '3'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
    restart: always

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nginx-proxy-le
    depends_on:
      - nginx-proxy
    volumes:
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam:ro
      - certs:/etc/nginx/certs
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: always

volumes:
  conf:
  vhost:
  html:
  dhparam:
  certs:

networks:
  default:
    external:
      name: nginx-proxy

docker-compose


$sudo docker-compose up -d

Minecraft installation

Use itzg/minecraft-server on Docker Hub. The directory to put Dynmap is the mods directory. Execute the following in the directory where docker-compose.yml is placed.

mkdir


$sudo mkdir mods

Minecraft docker-compose.yml is below. Match the Docker network name with docker-letsencrypt-nginx-proxy-companion.

docker-compose.yml


version: "3.7"

services:
  mc:
    image: itzg/minecraft-server
    ports:
    - 25565:25565
    - 8123:8123
    environment:
      EULA: "TRUE"
      VERSION: 1.16.4
      DIFFICULTY: normal
      SERVER_NAME: SERVERNAME
      TYPE: FORGE
      FORGEVERSION: 35.1.32
      ANNOUNCE_PLAYER_ACHIEVEMENTS: "true"
      TZ: Asia/Tokyo
      ENABLE_RCON: "true"
      RCON_PASSWORD: "PASSWORD"
      RCON_PORT: 28016
      ENABLE_QUERY: "true"
      ENABLE_STATUS: "true"
      OPS: Operator_Name
      USE_AIKAR_FLAGS: "true"
      MEMORY: 16G
      USE_LARGE_PAGES: "true"
      VIRTUAL_HOST: dynmap.your.domain
      VIRTUAL_PORT: 8123
      LETSENCRYPT_HOST: dynmap.your.domain
      LETSENCRYPT_EMAIL: email@address

    tty: true
    stdin_open: true
    restart: always

    volumes:
    - mc_forge:/data
    - ./mods:/mods:ro

volumes:
  mc_forge: {}

networks:
  default:
    external:
      name: nginx-proxy

Each item is explained below. Some items may not be necessary depending on the environment, so delete them as appropriate. In addition, please refer to the link below for details of variables related to the game (difficulty level, etc.). server.properties(Minecraft WIKI)

** Minecraft related **

Environment variable This time value Explanation
EULA "TRUE" Agree to Minecraft license (required)
VERSION 1.16.4 Minecraft version
DIFFICULTY normal Game difficulty
SERVER_NAME SERVERNAME Server name
TYPE FORGE The type of server. This time Forge.
FORGEVERSION 35.1.32 Forge version
ANNOUNCE_PLAYER_ACHIEVEMENTS "true" Whether to display player achievements (optional)
TZ Asia/Tokyo Time zone
ENABLE_RCON "true" Enable RCON (remote control of Minecraft)
RCON_PASSWORD "PASSWORD" RCON password
RCON_PORT 28016 RCON port number
ENABLE_QUERY "true" Enable sending server health
ENABLE_STATUS "true" Server details? Enable operation status transmission
OPS Operator_Name Server operator (OP authority) user settings
USE_AIKAR_FLAGS "true" Java variable optimization
MEMORY 16G Memory allocated by Java
USE_LARGE_PAGES "true" Java large page settings (memory 12GB or more)

** Dynamap/Reverse proxy/Let's Encrypt related **

Environment variable This time value Explanation
VIRTUAL_HOST dynmap.your.domain FQDN to display dynmap
VIRTUAL_PORT 8123 dynmap port number
LETSENCRYPT_HOST dynmap.your.domain FQDN to display dynmap
LETSENCRYPT_EMAIL email@address Let'Email address to be contacted by s Encrypt

Then store the dynmap in the mods directory. Please download it from the following and put it in the mods directory. https://www.curseforge.com/minecraft/mc-mods/dynmapforge

After that, docker-compose up and Minecraft will start.

docker-compose


$sudo docker-compose up -d

After a while (about 1 minute) after startup, it will be converted to https by docker-letsencrypt-nginx-proxy-companion. You should be able to access it at https : //dynmap.your.domain/. Minecraft itself can be connected with "your.domain" as usual if it is the default port.

If it doesn't start, please check the Docker log.

docker-compose


$sudo docker-compose logs -f 

** Certificate example ** dynmap_example.png

** Minecraft connection example ** server_example.png

in conclusion

Building a simple Minecraft server wasn't difficult in the first place, Minecraft can also be managed as IaC by running it in a container. It's nice to be able to quickly build the Minecraft environment you want. Also, dynmap could be reverse proxyed by setting the config, but it can be done more easily with the container version of Minecraft. Have a good Minecraft life!

Bonus: In my environment, I also use Prometheus and Grafana to check the player's status and play! example.png

Recommended Posts

Build a container version of Minecraft server and use https-enabled Dynmap
Build a Minecraft server on AWS
The story of building a Java version of Minecraft server with GCP (and also set a whitelist)
Set Java version 11 of Docker Minecraft Paper server
Build a docker container for a python simple web server
[CentOS] Download and build the specified version of Git
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
Use Jenkins to build inside Docker and then create a Docker image.
Proper use of redirect_to and render
Proper use of Mockito and PowerMock
About Docker, disguise server and container
Make a daily build of the TOPPERS kernel with Gitlab and Docker
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)