Dockerなら、ホントに簡単にマイクラサーバーがたてれます!
ちゃんとDocker用のマイクライメージがホストされてます。
Docker Hub itzg/minecraft-server
docker-composeの作成
docker run コマンドを直接実行するよりは、やはりcomposeで実行してしまうのが良いです。
docker-compose.yml という名前で以下のファイルを用意。
version: '2'
services:
minecraft-server:
container_name: mc
image: itzg/minecraft-server
ports:
- "25565:25565"
tty: true
stdin_open: true
restart: always
volumes:
- ./data:/data
environment:
EULA: "TRUE"
コンテナの起動
起動時にはこれだけで、イメージがダウンロードされて、コンテナが起動します。
簡単ですね!
# 起動
docker-compose up -d
# ステータス確認
docker-compose ps
# 停止
docker-compose down
$ docker-compose ps
Name Command State Ports
------------------------------------------------------------
mc /start Up 0.0.0.0:25565- 25565/tcp, 25575/tcp
データの永続化
docker-compose.ymlに記載した、volumesに
ホストの ./data ディレクトリと
コンテナの /data ディレクトリをマッピングしているので、
一度起動するとデータは永続化されます。
volumes:
- ./data:/data
./data配下はこんな感じ
$ ls -l ./data/
-rw-r--r-- 1 tyabuta tyabuta 2 9月 16 02:52 banned-ips.json
-rw-r--r-- 1 tyabuta tyabuta 2 9月 16 02:52 banned-players.json
drwxr-xr-x 2 tyabuta tyabuta 4096 9月 16 02:52 config
-rw-r--r-- 1 tyabuta tyabuta 65 9月 16 02:52 eula.txt
drwxr-xr-x 2 tyabuta tyabuta 4096 9月 16 10:43 logs
-rw-r--r-- 1 tyabuta tyabuta 30221337 9月 16 02:52 minecraft_server.1.12.1.jar
drwxrwxr-x 2 tyabuta tyabuta 4096 9月 16 02:48 mods
-rw-r--r-- 1 tyabuta tyabuta 2 9月 16 02:52 ops.json
-rw-rw-r-- 1 tyabuta tyabuta 860 9月 16 02:52 server.properties
-rw-r--r-- 1 tyabuta tyabuta 212 9月 16 12:43 usercache.json
-rw-r--r-- 1 tyabuta tyabuta 2 9月 16 02:52 whitelist.json
drwxr-xr-x 9 tyabuta tyabuta 4096 9月 17 00:08 world
server.properties をいじったり、
worldディレクトリを削除すればもう一度ワールドを生成しなおしてくれそう。
modsディレクトリ
どうやら、このイメージ
Minecraft Forgeが既に適用されているみたいなので、
いれたいMODは mods ディレクトリに入れて起動し直すだけでよいみたい。
超便利!!
ちなみに、ExtendRenderDistance というMODを入れて、
server.propertiesの、
view-distance=32 としたら、結構な範囲まで描画してくれるようになった♪
(最大15までしか設定できないところ)
やっぱり高いところに登って、世界を見渡せた方がいいよね〜。
おしまい
CPUとメモリは結構必要になるので、IDCフロンティアの月額500円程度のスペックではやはり厳しかったです。
コアが複数あって、2G以上のメモリは必要だろうね。
$ docker stats
CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1a70c843a499 41.83% 1.322GiB / 15.56GiB 8.50% 225MB / 676MB 4.1kB / 28.1MB 40