Public | Automated Build

Last pushed: 8 days ago
Short Description
Minecraft server with select-able version
Full Description


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 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

Interacting with the server

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

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.

NOTE: By default, the files in the attached directory will be owned by the host user with UID of 1000 and host group with GID of 1000.
You can use an different UID and GID by passing the options:

-e UID=1000 -e GID=1000

replacing 1000 with a UID and GID that is present on the host.
Here is one way to find the UID and GID:

id some_host_user
getent group some_host_group

Versions

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

  • LATEST
  • 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 ...

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 VERSION=1.7.10 \
    -e TYPE=FORGE -e FORGEVERSION=10.13.4.1448 \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

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
└── ...

If you add mods 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.

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.

Running a Bukkit/Spigot server

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

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

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

NOTE: to avoid pegging the CPU when running Spigot, you will need to
pass --noconsole at the very end of the command line and not use -it. For example,

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

You can install Bukkit plugins in two ways...

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 plugins to the /path/on/host/plugins folder you chose. From the example above,
the /path/on/host folder contents look like:

/path/on/host
├── plugins
│   └── ... INSTALL PLUGINS HERE ...
├── ops.json
├── server.properties
├── whitelist.json
└── ...

If you add plugins 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 is one additional volume that can be mounted; /plugins.
Any files in this filesystem will be copied over to the main
/data/plugins filesystem before starting Minecraft.

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

Running a PaperSpigot server

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

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

NOTE: to avoid pegging the CPU when running PaperSpigot, you will need to
pass --noconsole at the very end of the command line and not use -it. For example,

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

You can install Bukkit plugins in two ways...

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 plugins to the /path/on/host/plugins folder you chose. From the example above,
the /path/on/host folder contents look like:

/path/on/host
├── plugins
│   └── ... INSTALL PLUGINS HERE ...
├── ops.json
├── server.properties
├── whitelist.json
└── ...

If you add plugins 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 is one additional volume that can be mounted; /plugins.
Any files in this filesystem will be copied over to the main
/data/plugins filesystem before starting Minecraft.

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

Running a Server with a Feed-The-Beast (FTB) modpack

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

You need to specify a modpack to run, using the FTB_SERVER_MOD environment
variable. An FTB server modpack is available together with its respective
client modpack on https://www.feed-the-beast.com under "Additional Files."
Because of the interactive delayed download mechanism on that web site, you
must manually download the server modpack. Copy the modpack to the /data
directory (see "Attaching data directory to host filesystem”).

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

$ docker run -d -v /path/on/host:/data -e TYPE=FTB \
    -e FTB_SERVER_MOD=FTBPresentsSkyfactory3Server_3.0.6.zip \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

Using the /data volume

You must use a persistent /data mount for this type of server.

To do this, you will need to attach the container's /data directory
(see "Attaching data directory to host filesystem”).

If the modpack is updated and you want to run the new version on your
server, you stop and remove the container:

docker stop mc
docker rm mc

Do not erase anything from your /data directory (unless you know of
specific mods that have been removed from the modpack). Download the
updated FTB server modpack and copy it to /data. Start a new container
with FTB_SERVER_MOD specifying the updated modpack file.

$ docker run -d -v /path/on/host:/data -e TYPE=FTB \
    -e FTB_SERVER_MOD=FTBPresentsSkyfactory3Server_3.0.7.zip \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

FTB server JVM options

An FTB server modpack contains its own startup script that launches the
JVM and it does not use the JVM_OPTS environment variable. Instead
you can use MIN_RAM and MAX_RAM variables. These are appended to
the JVM -Xms and -Xmx options. For example, -e MIN_RAM=2G results
in -Xms2G passed to the JVM.

Additionally, PERMGEN_SIZE is passed on to -XX:PermSize. Here is an
example:

$ docker run -d -v /path/on/host:/data -e TYPE=FTB \
    -e MIN_RAM=1G -e MAX_RAM=2G -e PERMGEN_SIZE=512M \
    -e FTB_SERVER_MOD=FTBPresentsSkyfactory3Server_3.0.6.zip \
    -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server

Note: The FTB server start script will also override other options,
like MOTD.

Using Docker Compose

Rather than type the server options below, the port mappings above, etc
every time you want to create new Minecraft server, you can now use
Docker Compose. Start with a
docker-compose.yml file like the following:

minecraft-server:
  ports:
    - "25565:25565"

  environment:
    EULA: "TRUE"

  image: itzg/minecraft-server

  container_name: mc

  tty: true
  stdin_open: true
  restart: always

and in the same directory as that file run

docker-compose -d up

Now, go play...or adjust the environment section to configure
this server instance.

Server configuration

Difficulty

The difficulty level (default: easy) can be set like:

docker run -d -e DIFFICULTY=hard ...

Valid values are: peaceful, easy, normal, and hard, and an
error message will be output in the logs if it's not one of these
values.

Whitelist Players

To whitelist players for your Minecraft server, pass the Minecraft usernames separated by commas via the WHITELIST environment variable, such as

docker run -d -e WHITELIST=user1,user2 ...

If the WHITELIST environment variable is not used, any user can join your Minecraft server if it's publicly accessible.

Op/Administrator Players

To add more "op" (aka adminstrator) users to your Minecraft server, pass the Minecraft usernames separated by commas via the OPS environment variable, such as

docker run -d -e OPS=user1,user2 ...

Server icon

A server icon can be configured using the ICON variable. The image will be automatically
downloaded, scaled, and converted from any other image format:

docker run -d -e ICON=http://..../some/image.png ...

Rcon

To use rcon use the ENABLE_RCON and RCON_PASSORD variables.
By default rcon port will be 25575 but can easily be changed with the RCON_PORT variable.

docker run -d -e ENABLE_RCON=true -e RCON_PASSWORD=testing

Query

Enabling this will enable the gamespy query protocol.
By default the query port will be 25565 (UDP) but can easily be changed with the QUERY_PORT variable.

docker run -d -e ENABLE_QUERY=true

Max players

By default max players is 20, you can increase this with the MAX_PLAYERS variable.

docker run -d -e MAX_PLAYERS=50

Max world size

This sets the maximum possible size in blocks, expressed as a radius, that the world border can obtain.

docker run -d -e MAX_WORLD_SIZE=10000   

Allow Nether

Allows players to travel to the Nether.

docker run -d -e ALLOW_NETHER=true

Announce Player Achievements

Allows server to announce when a player gets an achievement.

docker run -d -e ANNOUNCE_PLAYER_ACHIEVEMENTS=true   

Enable Command Block

Enables command blocks

 docker run -d -e ENABLE_COMMAND_BLOCK=true

Force Gamemode

Force players to join in the default game mode.

  • false - Players will join in the gamemode they left in.
  • true - Players will always join in the default gamemode.

    docker run -d -e FORCE_GAMEMODE=false

Generate Structures

Defines whether structures (such as villages) will be generated.

  • false - Structures will not be generated in new chunks.
  • true - Structures will be generated in new chunks.

    docker run -d -e GENERATE_STRUCTURES=true

Hardcore

If set to true, players will be set to spectator mode if they die.

docker run -d -e HARDCORE=false

Max Build Height

The maximum height in which building is allowed.
Terrain may still naturally generate above a low height limit.

docker run -d -e MAX_BUILD_HEIGHT=256

Max Tick Time

The maximum number of milliseconds a single tick may take before the server watchdog stops the server with the message, A single server tick took 60.00 seconds (should be max 0.05); Considering it to be crashed, server will forcibly shutdown. Once this criteria is met, it calls System.exit(1).
Setting this to -1 will disable watchdog entirely

docker run -d -e MAX_TICK_TIME=60000

Spawn Animals

Determines if animals will be able to spawn.

docker run -d -e SPAWN_ANIMALS=true

Spawn Monsters

Determines if monsters will be spawned.

docker run -d -e SPAWN_MONSTERS=true

Spawn NPCs

Determines if villagers will be spawned.

docker run -d -e SPAWN_NPCS=true

View Distance

Sets the amount of world data the server sends the client, measured in chunks in each direction of the player (radius, not diameter).
It determines the server-side viewing distance.

docker run -d -e VIEW_DISTANCE=10

Level Seed

If you want to create the Minecraft level with a specific seed, use SEED, such as

docker run -d -e SEED=1785852800490497919 ...

Game Mode

By default, Minecraft servers are configured to run in Survival mode. You can
change the mode using MODE where you can either provide the standard
numerical values
or the
shortcut values:

  • creative
  • survival
  • adventure
  • spectator (only for Minecraft 1.8 or later)

For example:

docker run -d -e MODE=creative ...

Message of the Day

The message of the day, shown below each server entry in the UI, can be changed with the MOTD environment variable, such as

docker run -d -e 'MOTD=My Server' ...

If you leave it off, the last used or default message will be used. The example shows how to specify a server
message of the day that contains spaces by putting quotes around the whole thing.

PVP Mode

By default, servers are created with player-vs-player (PVP) mode enabled. You can disable this with the PVP
environment variable set to false, such as

docker run -d -e PVP=false ...

Level Type and Generator Settings

By default, a standard world is generated with hills, valleys, water, etc. A different level type can
be configured by setting LEVEL_TYPE to

  • DEFAULT
  • FLAT
  • LARGEBIOMES
  • AMPLIFIED
  • CUSTOMIZED

Descriptions are available at the gamepedia.

When using a level type of FLAT and CUSTOMIZED, you can further configure the world generator
by passing custom generator settings.
Since generator settings usually have ;'s in them, surround the -e value with a single quote, like below.

For example (just the -e bits):

-e LEVEL_TYPE=flat -e 'GENERATOR_SETTINGS=3;minecraft:bedrock,3*minecraft:stone,52*minecraft:sandstone;2;'

World Save Name

You can either switch between world saves or run multiple containers with different saves by using the LEVEL option,
where the default is "world":

docker run -d -e LEVEL=bonus ...

NOTE: if running multiple containers be sure to either specify a different -v host directory for each
LEVEL in use or don't use -v and the container's filesystem will keep things encapsulated.

Downloadable world

Instead of mounting the /data volume, you can instead specify the URL of
a ZIP file containing an archived world. This will be downloaded, and
unpacked in the /data directory; if it does not contain a subdirectory
called world/ then it will be searched for a file level.dat and the
containing subdirectory renamed to world. This means that most of the
archived Minecraft worlds downloadable from the Internet will already be in
the correct format.

The ZIP file may also contain a server.properties file and modules
directory, if required.

docker run -d -e WORLD=http://www.example.com/worlds/MySave.zip ...

NOTE: Unless you also mount /data as an external volume, this world
will be deleted when the container is deleted.

NOTE: This URL must be accessible from inside the container. Therefore,
you should use an IP address or a globally resolveable FQDN, or else the
name of a linked container.

Downloadable mod/plugin pack for Forge, Bukkit, and Spigot Servers

Like the WORLD option above, you can specify the URL of a "mod pack"
to download and install into mods for Forge or plugins for Bukkit/Spigot.
To use this option pass the environment variable MODPACK, such as

docker run -d -e MODPACK=http://www.example.com/mods/modpack.zip ...

NOTE: The referenced URL must be a zip file with one or more jar files at the
top level of the zip archive. Make sure the jars are compatible with the
particular TYPE of server you are running.

Online mode

By default, server checks connecting players against Minecraft's account database. If you want to create an offline server or your server is not connected to the internet, you can disable the server to try connecting to minecraft.net to authenticate players with environment variable ONLINE_MODE, like this

docker run -d -e ONLINE_MODE=FALSE ...

Miscellaneous Options

Memory Limit

By default, the image declares a Java initial and maximum memory limit of 1 GB. There are several
ways to adjust the memory settings:

  • MEMORY, "1G" by default, can be used to adjust both initial (Xms) and max (Xmx)
    memory settings of the JVM
  • INIT_MEMORY, independently sets the initial heap size
  • MAX_MEMORY, independently sets the max heap size

The values of all three are passed directly to the JVM and support format/units as
<size>[g|G|m|M|k|K].

/data ownership

In order to adapt to differences in UID and GID settings the entry script will attempt to correct ownership and writability of the /data directory. This logic can be disabled by setting -e SKIP_OWNERSHIP_FIX=TRUE.

Docker Pull Command
Owner
itzg
Source Repository

Comments (40)
stelk
3 days ago

I am playing a FTB modpack and want to enable BIOMES O PLENTY. Normally I would update the LEVEL_TYPE to BIOMESOP. However, this does not pass your validation code and throws an error. Is there a way to enable this mod using your docker script?

urgedtaylor
3 days ago

Is there a way to change it so I can use jstack/jmap from bash inside the container? Right now it just says the commands don't exist, I'm new to all this. Thanks

orekdm
14 days ago

I'm having trouble getting the expected behavior from docker commit/save/load operations. What is the recommended method for backing up a long running container with all necessary data? The goal is to have a full backup in case of VPS failure.

tarquin
24 days ago

Thanks for the fix.
Also -e FORGEVERSION= does not work, but -e VERSION= does.

tarquin
a month ago

Error: Unable to access jarfile forge-1.11.2--universal.jar
Has the version format changed again? I'm able to run a Bukkit server OK, but can't get Forge working.

exetico
a month ago

Hi'

You need to put in the "-d" after "up" when using "docker-compose" like:
"docker-compose up -d" :-)

tsutsarin
5 months ago

How can I specify JVM_OPTS in docker-compose.yml or .env file?

chinthor
7 months ago

Firstly, I figured it out. Had to get the "docker logs test" and see where it was hitting an error. Done. I've had a forge server running off and on for weeks with ~150 mods. I've also managed to run 3 such servers at the same time, each with different memory requirements and game versions. Great.

However, I ran into trouble while doing some testing. Long story short, I'm trying to duplicate my primary server and run tests on the clone. As root (sudo su) I copied the /test folder to /test2. I then made a new container and gave it a new port to operate on. But it doesn't matter if the original is running or not, I keep getting this error spammed in the console every 30 seconds.

WARNING: Could not lock User prefs. Unix error code 2.
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

So far, the only information I found on that error has to do with permissions, or the user not having a /home directory. And while user:minecraft might not, I don't get this error when running the original. And docker runs as root and minecraft runs as root and I kick off these containers and copy my files as root. I know it may be bad file security, but I should have no permission problems ever. Thoughts?

chinthor
7 months ago

Forgive my noob ignorance. Still learning how docker works at all. Can this image use any version of minecraft? I have modpacks that run on 1.6.4, 1.7.10, and 1.10. I got a "vanilla" forge server running in my tests. But trying to start my 1.6.4 container just returns the container name and then nothing. I'm told it is still stopped.

Here's the code I ran:
docker run -d -it -v /home/<redacted>/downlaods/dervers/test:/data -p 25566:25565 -e VERSION=1.6.4 -e TYPE-FORGE -e EULA=TRUE --name test itzg/minecraft-server

docker start test
(returns "test")
docker attach test
(returns "You cannot attach to a stopped container, start it first")

The necessary forge files did get created in the /test folder. Eula.txt reads true, so also tried building the container without that bit. Same result. Coppied my personal 1.6.4 server files into the /test folder. Same result.

Any ideas?

saranicole
7 months ago

Love this image! So fun! For Ansible users, I created a playbook (https://github.com/saranicole/stem-minecraft) that spools up a droplet on Digital Ocean, then runs the Docker container so you can get your Minecraft server running with minimal fuss. Thanks itzg for the inspiration!