• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

awesome-release/docker-minecraft-server: Docker minecraft server

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

awesome-release/docker-minecraft-server

开源软件地址(OpenSource Url):

https://github.com/awesome-release/docker-minecraft-server

开源编程语言(OpenSource Language):

Shell 95.2%

开源软件介绍(OpenSource Introduction):

Verified to work in Release

This project is based on https://github.com/itzg/docker-minecraft-server

No modifications were necessary for this project to run in Release. However, in the Release Application Template it is necessary to adjust a few things.

First, create an ELB to expose port 25565 with a simple hostname under the minecraft service. The minecraft service section of your Application Template should look like this:

services:
- name: minecraft
  image: itzg/minecraft-server
  ports:
  - port: '25565'
    type: node_port
    target_port: '25565'
    loadbalancer: true
  hostname: minecraft-${env_id}-lb-${domain}

This will expose port 25565 directly via an ELB to the Internet.

You should also increase the memory available for this container in Release by editing the resources section of your Applicaiton Template. In this example I've used 3Gb.

resources:
  cpu:
    limits: 1000m
    requests: 100m
  memory:
    limits: 3Gi
    requests: 100Mi
  replicas: 1

For more information on editing a Release Application Template, please refer to the documentation: Release Application Template Documentation.

Docker Pulls Docker Stars GitHub Issues Discord Build and Publish

This docker image provides a Minecraft Server that will automatically download the latest stable version at startup. You can also run/upgrade to any specific version or the latest snapshot. See the Versions section below for more information.

To simply use the latest stable version, run

docker run -d -p 25565:25565 --name mc -e EULA=TRUE itzg/minecraft-server

where the standard server port, 25565, will be exposed on your host machine.

If you want to serve up multiple Minecraft servers or just use an alternate port, change the host-side port mapping such as

docker run -p 25566:25565 ...

will serve your Minecraft server on your host's port 25566 since the -p syntax is host-port:container-port.

Speaking of multiple servers, it's handy to give your containers explicit names using --name, such as

docker run -d -p 25565:25565 --name mc itzg/minecraft-server

With that you can easily view the logs, stop, or re-start the container:

docker logs -f mc
    ( Ctrl-C to exit logs action )

docker stop mc

docker start mc

Be sure to always include -e EULA=TRUE in your commands, as Mojang/Microsoft requires EULA acceptance.

Looking for a Bedrock Dedicated Server

For Minecraft clients running on consoles, mobile, or native Windows, you'll need to use this image instead:

itzg/minecraft-bedrock-server

Interacting with the server

RCON is enabled by default, so you can exec into the container to access the Minecraft server console:

docker exec -i mc rcon-cli

Note: The -i is required for interactive use of rcon-cli.

To run a simple, one-shot command, such as stopping a Minecraft server, pass the command as arguments to rcon-cli, such as:

docker exec mc rcon-cli stop

The -i is not needed in this case.

In order to attach and interact with the Minecraft server, add -it when starting the container, such as

docker run -d -it -p 25565:25565 --name mc itzg/minecraft-server

With that you can attach and interact at any time using

docker attach mc

and then Control-p Control-q to detach.

For remote access, configure your Docker daemon to use a tcp socket (such as -H tcp://0.0.0.0:2375) and attach from another machine:

docker -H $HOST:2375 attach mc

Unless you're on a home/private LAN, you should enable TLS access.

EULA Support

Mojang now requires accepting the Minecraft EULA. To accept add

    -e EULA=TRUE

such as

    docker run -d -it -e EULA=TRUE -p 25565:25565 --name mc itzg/minecraft-server

Timezone Configuration

You can configure the timezone to match yours by setting the TZ environment variable:

    -e TZ=Europe/London

such as:

    docker run -d -it -e TZ=Europe/London -p 25565:25565 --name mc itzg/minecraft-server

Or mounting /etc/timezone as readonly (not supported on Windows):

    -v /etc/timezone:/etc/timezone:ro

such as:

    docker run -d -it -v /etc/timezone:/etc/timezone:ro -p 25565:25565 --name mc itzg/minecraft-server

Attaching data directory to host filesystem

In order to readily access the Minecraft data, use the -v argument to map a directory on your host machine to the container's /data directory, such as:

docker run -d -v /path/on/host:/data ...

When attached in this way you can stop the server, edit the configuration under your attached /path/on/host and start the server again with docker start CONTAINERID to pick up the new configuration.

Versions

To use a different Minecraft version, pass the VERSION environment variable, which can have the value

  • LATEST (the default)
  • SNAPSHOT
  • or a specific version, such as "1.7.9"

For example, to use the latest snapshot:

docker run -d -e VERSION=SNAPSHOT ...

or a specific version:

docker run -d -e VERSION=1.7.9 ...

When using "LATEST" or "SNAPSHOT" an upgrade can be performed by simply restarting the container. During the next startup, if a newer version is available from the respective release channel, then the new server jar file is downloaded and used. NOTE: over time you might see older versions of the server jar remain in the /data directory. It is safe to remove those.

Running Minecraft server on different Java version

To use a different version of Java, please use a docker tag to run your Minecraft server.

Tag name Description Linux
latest Default. Uses Java version 8 update 212 Alpine Linux
adopt14 Uses Java version 14 latest update Alpine Linux
adopt13 Uses Java version 13 latest update Alpine Linux
adopt11 Uses Java version 11 latest update Alpine Linux
openj9 Uses Eclipse OpenJ9 JVM Alpine Linux
openj9-nightly Uses Eclipse OpenJ9 JVM testing builds Alpine Linux
multiarch Uses Java version 8 latest update Debian Linux

For example, to use a Java version 13:

docker run --name mc itzg/minecraft-server:adopt13

Keep in mind that some versions of Minecraft server can't work on the newest versions of Java. Also, FORGE doesn't support openj9 JVM implementation.

Healthcheck

This image contains mc-monitor and uses its status command to continually check on the container's. That can be observed from the STATUS column of docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS                                 NAMES
b418af073764        mc                  "/start"            43 seconds ago      Up 41 seconds (healthy)   0.0.0.0:25565->25565/tcp, 25575/tcp   mc

You can also query the container's health in a script friendly way:

> docker container inspect -f "{{.State.Health.Status}}" mc
healthy

Some orchestration systems, such as Portainer, don't allow for disabling the default HEALTHCHECK declared by this image. In those cases you can approximate the disabling of healthchecks by setting the environment variable DISABLE_HEALTHCHECK to true.

Autopause (experimental)

Description

EXPERIMENTAL: this feature only works with default bridge networking using official Docker distributions. Host networking and container management software, such as Portainer, and NAS solutions do not seem to provide compatible networking.

There are various bug reports on Mojang about high CPU usage of servers with newer versions, even with few or no clients connected (e.g. this one, in fact the functionality is based on this comment in the thread).

An autopause functionality has been added to this image to monitor whether clients are connected to the server. If for a specified time no client is connected, the Java process is stopped. When knocking on the server port (e.g. by the ingame Multiplayer server overview), the process is resumed. The experience for the client does not change.

Of course, even loaded chunks are not ticked when the process is stopped.

From the server's point of view, the pausing causes a single tick to take as long as the process is stopped, so the server watchdog might intervene after the process is continued, possibly forcing a container restart. To prevent this, ensure that the max-tick-time in the server.properties file is set correctly.

On startup the server.properties file is checked and, if applicable, a warning is printed to the terminal. When the server is created (no data available in the persistent directory), the properties file is created with the Watchdog disabled.

A starting, example compose file has been provided in examples/docker-compose-autopause.yml.

Enabling Autopause

Enable the Autopause functionality by setting:

-e ENABLE_AUTOPAUSE=TRUE

There are 4 more environment variables that define the behaviour:

  • AUTOPAUSE_TIMEOUT_EST, default 3600 (seconds) describes the time between the last client disconnect and the pausing of the process (read as timeout established)
  • AUTOPAUSE_TIMEOUT_INIT, default 600 (seconds) describes the time between server start and the pausing of the process, when no client connects inbetween (read as timeout initialized)
  • AUTOPAUSE_TIMEOUT_KN, default 120 (seconds) describes the time between knocking of the port (e.g. by the main menu ping) and the pausing of the process, when no client connects inbetween (read as timeout knocked)
  • AUTOPAUSE_PERIOD, default 10 (seconds) describes period of the daemonized state machine, that handles the pausing of the process (resuming is done independently)

Deployment Templates and Examples

Helm Charts

Examples

The examples directory also provides examples of deploying the itzg/minecraft-server Docker image.

Amazon Web Services (AWS) Deployment

If you're looking for a simple way to deploy this to the Amazon Web Services Cloud, check out the Minecraft Server Deployment (CloudFormation) repository. This repository contains a CloudFormation template that will get you up and running in AWS in a matter of minutes. Optionally it uses Spot Pricing so the server is very cheap, and you can easily turn it off when not in use.

Running a Forge Server

Enable Forge server mode by adding a -e TYPE=FORGE to your command-line. By default the container will run the RECOMMENDED version of Forge server but you can also choose to run a specific version with -e FORGEVERSION=10.13.4.1448.

$ docker run -d -v /path/on/host:/data \
    -e TYPE=FORGE -e FORGEVERSION=10.13.4.1448 \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

To use a pre-downloaded Forge installer, place it in the attached /data directory and specify the name of the installer file with FORGE_INSTALLER, such as:

$ docker run -d -v /path/on/host:/data ... \
    -e FORGE_INSTALLER=forge-1.11.2-13.20.0.2228-installer.jar ...

To download a Forge installer from a custom location, such as your own file repository, specify the URL with FORGE_INSTALLER_URL, such as:

$ docker run -d -v /path/on/host:/data ... \
    -e FORGE_INSTALLER_URL=http://HOST/forge-1.11.2-13.20.0.2228-installer.jar ...

In both of the cases above, there is no need for the VERSION or FORGEVERSION variables.

In order to add mods, you have two options.

Using the /data volume

This is the easiest way if you are using a persistent /data mount.

To do this, you will need to attach the container's /data directory (see "Attaching data directory to host filesystem”). Then, you can add mods to the /path/on/host/mods folder you chose. From the example above, the /path/on/host folder contents look like:

/path/on/host
├── mods
│   └── ... INSTALL MODS HERE ...
├── config
│   └── ... CONFIGURE MODS HERE ...
├── ops.json
├── server.properties
├── whitelist.json
├── worlds
│   └── ... PLACE MAPS IN THEIR OWN FOLDERS HERE ...
└── ...

Providing a presistent /data mount is a good idea, both to persist the game world and to allow for the manual configuration which is sometimes needed.

For instance, imagine a scenario when the initial launch has completed, but you now want to change the worldmap for your server.

Assuming you have a shared directory to your container, you can then (after first launch) drag and drop your premade maps or worlds into the \worlds\ directory. Note: each world should be placed in its own folder under the \worlds\ directory.

Once your maps are in the proper path, you can then specify which map the server uses by changing the level-name value in server.properties to match the name of your map.

If you add mods or make changes to server.properties while the container is running, you'll need to restart it to pick those up:

docker stop mc
docker start mc

Using separate mounts

This is the easiest way if you are using an ephemeral /data filesystem, or downloading a world with the WORLD option.

There are two additional volumes that can be mounted; /mods and /config. Any files in either of these filesystems will be copied over to the main /data filesystem before starting Minecraft. If you want old mods to be removed as the /mods content is updated, then add -e REMOVE_OLD_MODS=TRUE.

This works well if you want to have a common set of modules in a separate location, but still have multiple worlds with different server requirements in either persistent volumes or a downloadable archive.

Replacing variables inside configs

Sometimes you have mods or plugins that require configuration information that is only available at runtime. For example if you need to configure a plugin to connect to a database, you don't want to include this information in your Git repository or Docker image. Or maybe you have some runtime information like the server name that needs to be set in your config files after the container starts.

For those cases there is the option to replace defined variables inside your configs with environment variables defined at container runtime.

If you set the enviroment variable REPLACE_ENV_VARIABLES to TRUE the startup script will go thru all files inside your /data volume and replace variables that match your defined environment variables. Variables that you want to replace need to be wrapped inside ${YOUR_VARIABLE} curly brackets and prefixed with a dollar sign. This is the regular syntax for enviromment variables inside strings or config files.

Optionally you can also define a prefix to only match predefined environment variables.

ENV_VARIABLE_PREFIX="CFG_" <-- this is the default prefix

If you want use file for value (like when use secrets) you can add suffix _FILE to your variable name (in run command).

There are some limitations to what characters you can use.

Type Allowed Characters
Name 0-9a-zA-Z_-
Value 0-9a-zA-Z_-:/=?.+

Variables will be replaced in files with the following extensions: .yml, .yaml, .txt, .cfg, .conf, .properties.

Specific files can be excluded by listing their name (without path) in the variable REPLACE_ENV_VARIABLES_EXCLUDES.

Paths can be excluded by listing them in the variable REPLACE_ENV_VARIABLES_EXCLUDE_PATHS. Path excludes are recursive. Here is an example:

REPLACE_ENV_VARIABLES_EXCLUDE_PATHS="/data/plugins/Essentials/userdata /data/plugins/MyPlugin"

Here is a full example where we want to replace values inside a database.yml.

---
database:
  host: ${CFG_DB_HOST}
  name: ${CFG_DB_NAME}
  password: ${CFG_DB_PASSWORD}

This is how your docker-compose.yml file could look like:

version: "3"
# Other docker-compose examples in /examples

services:
  minecraft:
    image: itzg/minecraft-server
    ports:
      - "25565:25565"
    volumes:
      - "mc:/data"
    environment:
      EULA: "TRUE"
      ENABLE_RCON: "true"
      RCON_PASSWORD: "testing"
      RCON_PORT: 28016
      # enable env variable replacement
      REPLACE_ENV_VARIABLES: "TRUE"
      # define an optional prefix for your env variables you want to replace
      ENV_VARIABLE_PREFIX: "CFG_"
      # and here are the actual variables
      CFG_DB_HOST: "http://localhost:3306"
      CFG_DB_NAME: "minecraft"
      CFG_DB_PASSWORD_FILE: "/run/secrets/db_password"
    restart: always
  rcon:
    image: itzg/rcon
    ports:
      - "4326:4326"
      - "4327:4327"
    volumes:
      - "rcon:/opt/rcon-web-admin/db"

volumes:
  mc:
  rcon:

secrets:
  db_password:
    file: ./db_password

The content of db_password:

ug23u3bg39o-ogADSs

Running a Bukkit/Spigot server

Enable Bukkit/Spigot server mode by adding a -e TYPE=BUKKIT or -e TYPE=SPIGOT to your command-line.

docker run -d -v /path/on/host:/data \
    -e TYPE=SPIGOT \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

If you are hosting your own copy of Bukkit/Spigot you can override the download URLs with:

  • -e BUKKIT_DOWNLOAD_URL=
  • -e SPIGOT_DOWNLOAD_URL=

You can build spigot from source by adding -e BUILD_FROM_SOURCE=true

If you have attached a host directory to the /data volume, then you can install plugins within the plugins subdirectory. You can also attach a /plugins volume. If you add plugins while the container is running, you'll need to restart it to pick those up.

Running a Paper server

Enable Paper server mode by adding a -e TYPE=PAPER to your command-line.

By default the container will run the latest build of Paper server but you can also choose to run a specific build with -e PAPERBUILD=205.

docker run -d -v /path/on/host:/data \
    -e TYPE=PAPER \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

If you are hosting your own copy of Paper you can override the download URL with:

  • -e PAPER_DOWNLOAD_URL=

An example compose file is provided at examples/docker-compose-paper.yml.

If you have attached a host directory to the /data volume, then you can install plugins via the plugins subdirectory. You can also attach a /plugins volume. If you add plugins while the container is running, you'll need to restart it to pick those up.

Running a Tuinity server

A Tuinity server, which is a fork of Paper aimed at improving server performance at high playercounts.

-e TYPE=TUINITY

NOTE only VERSION=LATEST is supported

Running a Magma server

A Magma server, which is a combination of Forge and PaperMC, can be used with

-e TYPE=MAGMA

NOTE there are limited base versions supported, so you will also need to set VERSION, such as "1.12.2"

Running a Mohist server

A Mohist server can be used with

-e TYPE=MOHIST

NOTE there are limited base versions supported, so you will also need to set VERSION, such as "1.12.2"

Running a Catserver type server

A Catserver type server can be used with

-e TYPE=CATSERVER

NOTE Catserver only provides a single release stream, so VERSION is ignored

Running a server with a Feed the Beast modpack

NOTE requires itzg/minecraft-server:multiarch image

Feed the Beast application modpacks are supported by using -e TYPE=FTBA (note the "A" at the end of the type). This server type will automatically take care of downloading and installing the modpack and appropriate version of Forge, so the VERSION does not need to be specified.

Environment Variables:

  • FTB_MODPACK_ID: required, the numerical ID of the modpack to install. The ID can be located by finding the modpack and using the "ID" displayed next to the name
  • FTB_MODPACK_VERSION_ID: optional, the numerical Id of the version to install. If not specified, the latest version will be installed. The "Version ID" can be obtained by drilling into the Versions tab and clicking a specific version.

Upgrading

If a specific FTB_MODPACK_VERSION_ID was not specified, simply restart the container to pick up the newest modpack version. If using a specific version ID, recreate the container with the new version ID.

Example

The following example runs the latest version of FTB Presents Direwolf20 1.12:

docker run -d --name mc-ftb -e EULA=TRUE \
  -e TYPE=FTBA -e FTB_MODPACK_ID=31 \
  -p 25565:25565 \
  itzg/minecraft-server:multiarch

Normally you will also add -v volume for /data since the mods and config are installed there along with world data.

Running a server with a CurseForge modpack

Enable this server mode by adding -e TYPE=CURSEFORGE to your command-line, but note the following additional steps needed...

You need to specify a modpack to run, using the CF_SERVER_MOD environment variable. A CurseForge server modpack is available together with its respective client modpack at https://www.curseforge.com/minecraft/modpacks .

Now you can add a -e CF_SERVER_MOD=name_of_modpack.zip to your command-line.

docker run -d -v /path/on/host:/data -e TYPE=CURSEFORGE \
    -e CF_SERVER_MOD=SkyFactory_4_Server_4.1.0.zip \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

If you want to keep the pre-download modpacks separate from your data directory, then you can attach another volume at a path of your choosing and reference that. The following example uses /modpacks as the container path as the pre-download area:

docker run -d -v /path/on/host:/data -v /path/to/modpacks:/modpacks \
    -e TYPE=CURSEFORGE \
    -e CF_SERVER_MOD=/modpacks/SkyFactory_4_Server_4.1.0.zip \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

Buggy start scripts


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap