selfhosted-apps-docker/minecraft/readme.md

302 lines
10 KiB
Markdown
Raw Normal View History

2022-08-28 17:09:34 +00:00
# Minecraft server in docker
###### guide-by-example
2022-08-29 14:20:41 +00:00
![logo](https://i.imgur.com/VphJTKG.png)
2022-08-28 17:09:34 +00:00
# Purpose & Overview
2022-09-09 15:38:19 +00:00
A game - open world, building, survival.
2022-08-28 17:09:34 +00:00
* [Official site](https://www.minecraft.net/en-us)
2022-09-09 15:38:19 +00:00
* [itzg github](https://github.com/itzg/docker-minecraft-server)
2022-08-28 17:09:34 +00:00
2022-08-29 14:27:13 +00:00
Minecraft is written in Java.<br>
2022-09-09 15:38:19 +00:00
This setup is using [itzg](https://github.com/itzg/docker-minecraft-server)
maintend docker image. Specificly [Purpur](https://purpurmc.org/docs/)
2022-09-25 09:02:28 +00:00
version which is a fork of
2022-10-31 07:54:58 +00:00
[Paper](https://www.spigotmc.org/wiki/what-is-spigot-craftbukkit-bukkit-vanilla-forg/)
which is a fork of [Spigot](https://www.spigotmc.org/wiki/what-is-spigot-craftbukkit-bukkit-vanilla-forg/).
2022-09-09 15:38:19 +00:00
Few plugings are used which allow to host multiple worlds on the same server.<br>
Also [docker-rcon-web-admin](https://github.com/itzg/docker-rcon-web-admin)
container is runnig to be able to do basic console tasks from web interface.
This setup is written in september 2022 with 1.19.2 being the latest build.
2022-08-28 17:09:34 +00:00
# Files and directory structure
```
/home/
└── ~/
└── docker/
└── minecraft/
├── minecraft-data/
├── .env
└── docker-compose.yml
```
2022-09-09 15:38:19 +00:00
* `minecraft-data/` - a directory where minecraft stores its data
2022-08-28 17:09:34 +00:00
* `.env` - a file containing environment variables for docker compose
2022-09-09 15:38:19 +00:00
* `docker-compose.yml` - a compose file, telling docker how to build containers
2022-08-28 17:09:34 +00:00
You only need to provide the files.</br>
The directory is created by docker compose on the first run.
# docker-compose
`docker-compose.yml`
```yml
services:
minecraft:
image: itzg/minecraft-server
container_name: minecraft
hostname: minecraft
restart: unless-stopped
env_file: .env
tty: true
stdin_open: true
ports:
2022-09-25 09:02:28 +00:00
- 25565:25565 # minecraft server players connect
- 25575:25575 # rcon connection
- 8100:8100 # bluemap
- 8123:8123 # dynmap
2022-08-28 17:09:34 +00:00
volumes:
- ./minecraft-data:/data
2023-01-05 00:56:45 +00:00
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
2022-09-09 15:38:19 +00:00
2022-09-25 09:02:28 +00:00
minecraft-rcon:
2022-09-09 15:38:19 +00:00
image: itzg/rcon
2022-09-25 09:02:28 +00:00
container_name: minecraft-rcon
hostname: minecraft-rcon
2022-09-09 15:38:19 +00:00
restart: unless-stopped
env_file: .env
2022-09-25 09:02:28 +00:00
depends_on:
- minecraft
2022-09-09 15:38:19 +00:00
ports:
- 4326:4326
- 4327:4327
networks:
default:
name: $DOCKER_MY_NETWORK
external: true
2022-08-28 17:09:34 +00:00
```
`.env`
```bash
# GENERAL
MY_DOMAIN=example.com
DOCKER_MY_NETWORK=caddy_net
TZ=Europe/Bratislava
2022-09-09 15:38:19 +00:00
# ITZG MINECRAFT SPECIFIC
2022-08-28 17:09:34 +00:00
TYPE=PURPUR
EULA=TRUE
ONLINE_MODE=FALSE
SNOOPER_ENABLED=FALSE
SERVER_NAME=Blablabla
ALLOW_CHEATS=TRUE
MAX_MEMORY=3G
MAX_PLAYERS=50
ENABLE_COMMAND_BLOCK=TRUE
ALLOW_NETHER=TRUE
2022-09-09 15:38:19 +00:00
# ITZG RCON WEB ADMIN SPECIFIC
2022-09-25 09:02:28 +00:00
RWA_ENV=TRUE
RWA_USERNAME=admin
RWA_PASSWORD=admin
RWA_ADMIN=TRUE
RWA_RCON_HOST=minecraft
RWA_RCON_PASSWORD=minecraft
RWA_WEBSOCKET_URL: "ws://rcon.example.com/ws"
RWA_WEBSOCKET_URL_SSL: "wss://rcon.example.com/ws"
2022-08-28 17:09:34 +00:00
```
2022-08-29 14:29:40 +00:00
# Port forwarding
2022-08-28 17:09:34 +00:00
2022-08-29 14:29:40 +00:00
You **must forward port 25565** on your firewall to your docker host
if you want it world accessible.<br>
2022-09-09 15:38:19 +00:00
# Reverse proxy
Caddy v2 is used, details
[here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/caddy_v2).</br>
The minecraft server itself does not need this, but plugins do.
2022-09-13 07:02:53 +00:00
First one is bluemap/dynmap, to see real time map of the world.<br>
2022-09-09 15:38:19 +00:00
Second one is for rcon web admin, to be able to quickly manage server from anywhere.
`Caddyfile`
```
map.{$MY_DOMAIN} {
reverse_proxy minecraft:8123
}
rcon.{$MY_DOMAIN} {
2022-09-25 09:16:39 +00:00
reverse_proxy /ws minecraft-rcon:4327
reverse_proxy minecraft-rcon:4326
2022-09-09 15:38:19 +00:00
}
```
2022-08-29 14:27:13 +00:00
# Domain
2022-08-29 14:29:40 +00:00
Setup a DNS A-record for you subdomain - `minecraft.example.com`
2022-08-29 14:27:13 +00:00
Will work fine if using default port `25565`<br>
2022-08-29 14:31:41 +00:00
If you would want to use a different port, but also would prefer your users
2022-08-29 14:27:13 +00:00
to not need to enter `minecraft.example.com:30108` then google
2022-08-29 14:31:41 +00:00
"minecraft srv record" and you should find correct settings.<br>
2022-08-29 14:29:40 +00:00
Like [this one](https://i.imgur.com/hDhZQ.png).
2022-08-28 17:09:34 +00:00
# Plugins
* [multiverse core](https://dev.bukkit.org/projects/multiverse-core)
* [multiverse portals](https://dev.bukkit.org/projects/multiverse-portals)
* [multiverse inventory](https://dev.bukkit.org/projects/multiverse-inventories)
2022-09-09 15:38:19 +00:00
* [multiverse netherportals](https://dev.bukkit.org/projects/multiverse-netherportals/)
* [EssentialsX](https://essentialsx.net/downloads.html) *(switch to stable tab)*
2022-08-28 17:09:34 +00:00
* [EssentialsX Spawn](https://essentialsx.net/downloads.html)
2022-09-09 15:38:19 +00:00
Why the plugins?<br>
2022-08-28 18:03:07 +00:00
You want one server but you want people to be able to play creative or surival?<br>
2022-08-28 17:14:00 +00:00
Well you need `multiverse core`.<br>
2022-08-28 17:09:34 +00:00
How do the people move between these worlds?<br>
2022-08-29 14:16:31 +00:00
Well you need `multiverse portals`.<br>
2022-08-28 17:14:00 +00:00
Should they be able to bring stuff from one world to another? No?<br>
2022-08-28 18:04:18 +00:00
Well you need `multiverse inventory`.<br>
2022-09-09 15:38:19 +00:00
Should the connecting of worlds with their nether be easy?<br>
Well you need `multiverse netherportals`.<br>
2022-10-31 07:54:58 +00:00
Should they spawn in lobby on start,
2022-08-28 17:14:00 +00:00
but also remember the position in the worlds when entering portals?<br>
2022-08-29 14:16:31 +00:00
Well you need the rest of that shit, `EssentialsX` and `EssentialsX Spawn`.
2022-08-28 17:09:34 +00:00
2022-08-28 17:14:00 +00:00
**Plugins installation** - place the downloaded jar files in to
2022-08-28 18:03:07 +00:00
`~/docker/minecraft/minecraft-data/plugins`<br>
2022-08-28 17:14:00 +00:00
restart the server
2022-08-28 17:09:34 +00:00
2022-08-29 14:16:31 +00:00
# The setup
2022-08-28 18:03:07 +00:00
2022-08-29 14:16:31 +00:00
check if the plugins are loaded using command `plugins`
2022-08-28 17:09:34 +00:00
2022-08-29 14:16:31 +00:00
### creation of the worlds
* check the worlds present - `mv list`<br>
these 3 existing worlds [world, nether, end] are grouped and interconnected
and will be used as the survival world
* create a new world called **"creative_world"** - `mv create creative_world normal`
* teleport to it - `mv tp creative_world`
* switch mode to creative - `mvm set mode creative creative_world`
* create a new world called **"lobby"** - `mv create lobby normal -t flat`
* teleport to lobby world - `mv tp lobby`
* remove monsters - `mvm set difficulty peaceful`
* remove animals - `mv modify set animals false`
* set adventure - `mvm set mode adventure`
* **build 2 portals**, for survival and creative worlds
* get worldedit axe using command - `mvp wand`
* use left click and right click to select portal area<br>
after selecting it create a portal named portal1 with destination creative_world -
`mvp create portal1 creative_world`
* same thing with the axe for survival, with destination to "world" -
`mvp create portal2 world`
* you can check your portals configuration on server in `> plugins > multiverse-portals > config.yml`
* if **non OP players** cant use portals execute -
`mvp conf enforceportalaccess false` or `mv conf enforceaccess false`
*bonus info*<br>
if you have seed `mv create snow_world normal -s -5343926151482505487`
### spawning in the worlds
* pick a spawn point in the lobby and set it with multiple commands
* `setspawn`
* `setworldspawn`
* `mv setspawn`
* edit the file in `> plugins > Essentials > config.yml`<br>
`setspawn-on-join: true`
* you would think we are done with spawns, but nope, fuck you,
this all lets the game start in spawn location in the lobby world,
but when entering creative world you would be starting from its spawn,
instead of last position on exit. So... heres how to fix that.
* this command for the inventory plugin makes the world remember last location
`mvinv toggle last_location`<br>
but with just that change the lobby world position is also remembered
and users end up spawning inside of portals instead of specific spawn
* to fix that we set in `> plugins > multiverse-inventories > config.yml`
`optionals_for_ungrouped_worlds: false`<br>
* but our lobby world is ungrouped, so we need to add it to a group
using command `mvinv group` and then following the instructions.
Writing the answers in to the console without slash, when it asks
about shares, giving `last_location` and ending with `@`<br>
[This](https://i.imgur.com/8yBh2Bz.png) could be helpful too,
but it feels like doing unnecessary steps
* now you should have spawn point in lobby that is always the same,
while after entering portals you end up at your last location
# Extra Plugins
* [AntiPopup](https://github.com/KaspianDev/AntiPopup) -
if you dont want that stupid chat popup so thats AntiPopup.<br>
2022-09-09 15:38:19 +00:00
* [Action Bar Health](https://www.spigotmc.org/resources/action-bar-health.2661/)
2022-09-18 12:42:59 +00:00
- see mobs health when you fight them,
in config I set `show on look` to false<br>
I prefered the look of holomobhealth, but its dependancy ProtocolLib is only
in beta at the moment, and might be causing issues on my server, did not investigate thoroughly
* [Bluemap](https://www.spigotmc.org/resources/bluemap.83557/) - map
of the world in web gui, real time.Default port 8100
----------
Something of this is causing server to ocasionally go to super high disk use
and needs restart. Not just container, but entire VM. Will maybe investigate.
2022-12-17 09:47:44 +00:00
/update, it was likely caused by using m.2 ssd for storing esxi VMs,
switch to sata ssd seems to prevent any more occurancies of this high disk usage
2022-09-09 15:38:19 +00:00
* [Dynmap](https://www.spigotmc.org/resources/dynmap%C2%AE.274/) - map
of the world in web gui, real time. Default port 8123
* [Chunky](https://www.spigotmc.org/resources/chunky.81534/) - pre-generates chunks
useful for dynmap to fill black patches
2022-09-18 12:42:59 +00:00
* [OpeNLogin](https://www.spigotmc.org/resources/openlogin-1-7x-1-19x.57272/)
* [luckperms](https://luckperms.net/download) - manage permissions of players,
2022-12-04 14:08:52 +00:00
planned to use, not in use yet. [Here](https://www.youtube.com/watch?v=AwbVqSOn2SI) is a good video on it.
2023-01-05 00:56:45 +00:00
luckpers commands
* `lp editor` - open browser editor, afterwards it should be confirmed
* set everything in browser
* in game `lp user Dunco parent set hráč`
2022-12-17 09:47:44 +00:00
* wordguard with word edit, followed [this video](https://youtu.be/pYAk38Hekqg)
2022-09-09 15:38:19 +00:00
2022-09-18 12:42:59 +00:00
# Comamnds & settings
2022-09-09 15:38:19 +00:00
2022-09-18 12:42:59 +00:00
* `/gamerule playersSleepingPercentage 1` - use bed whenever, sleep not dependant on other players
2022-09-09 15:38:19 +00:00
2022-08-28 17:09:34 +00:00
# Update
Manual image update:
- `docker-compose pull`</br>
- `docker-compose up -d`</br>
- `docker image prune`
# Backup and restore
#### Backup
Using [borg](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
that makes daily snapshot of the entire directory.
#### Restore
* down the minecraft container `docker-compose down`</br>
* delete the entire minecraft directory</br>
* from the backup copy back the minecraft directory</br>
* start the containers `docker-compose up -d`