Adding a new java to docker

Docker deployments of MineOS currently still only package a single Java version. This is causing issues because the latest Minecraft 1.17 does not run on this old version, while older versions of Minecraft do not run well on the newer Java.

This short tutorial will help docker users add Java to their server. Note, the steps to add Java to your existing non-docker server are pretty much the same, with regard to file locations and steps, but all the docker copying and volume portions would not apply.

This tutorial assumes you have a working MineOS docker deployment already.

  1. download the latest Java binary–specifically the compressed tarball file for your preferred architecture from Oracle.

  2. copy this file to your MineOS host (the host running the docker daemon).
    scp jdk-16.0.1_linux-x64_bin.tar.gz will@host:/home/will/

  3. copy this file into your docker instance using docker cp:

(In this example, container is named named mineos):
docker cp jdk-16.0.1_linux-x64_bin.tar.gz mineos:/var/games/minecraft/

  1. enter the container and extract the java binaries:
root@host # docker exec -it mineos /bin/bash
root@b260116662e0:/# cd /var/games/minecraft
root@b260116662e0:/var/games/minecraft# tar -xf jdk-16.0.1_linux-x64_bin.tar.gz 
root@b260116662e0:/var/games/minecraft# ls
archives    backups    servers     profiles
jdk-16.0.1     jdk-16.0.1_linux-x64_bin.tar.gz 
  1. Lastly, set the server to use this binary with the java_binary attribute in server.config. There are many ways to accomplish this, but I’ll choose the one that allows me to complete it within this session.
root@b260116662e0:/var/games/minecraft # cd /var/games/minecraft/servers/117serv/
root@b260116662e0:/var/games/minecraft/servers/117serv# cat server.config 
[java]
java_binary=
java_xmx=512
jarfile=minecraft_server.1.17.jar

[onreboot]
start=false

[minecraft]
profile=1.17
root@b260116662e0:/var/games/minecraft/servers/117serv# sed -i '2s|$|/var/games/minecraft/jdk-16.0.1/bin/java|' server.config 
[java]
java_binary=/var/games/minecraft/jdk-16.0.1/bin/java
java_xmx=512
jarfile=minecraft_server.1.17.jar

[onreboot]
start=false

[minecraft]
profile=1.17

  1. And then start the server!
[17:15:13] [Worker-Main-4/INFO]: Loaded 1137 advancements
[17:15:16] [Server thread/INFO]: Starting minecraft server version 1.17
[17:15:16] [Server thread/INFO]: Loading properties
[17:15:16] [Server thread/INFO]: Default game type: SURVIVAL
[17:15:16] [Server thread/INFO]: Generating keypair
[17:15:16] [Server thread/INFO]: Starting Minecraft server on 0.0.0.0:25565
[17:15:16] [Server thread/INFO]: Using epoll channel type
2 Likes

I was following these instructions and realized since you’re using the /opt directory, when you recreate the container, your opt directory will be wiped and you’ll need to follow these instructions again.

What I suggest is you install it to your config directory/volume so the java binaries is permanent.

the only key differences are the following:

follow the normal instructions but when you get to step 3, do the following instead

docker cp jdk-16.0.1_linux-x64_bin.tar.gz mineos:/

step 4

root@host:/ docker exec -it mineos /bin/bash
root@b260116662e0:/ mkdir /var/games/minecraft/java
root@b260116662e0:/ mv jdk-16.0.1_linux-x64_bin.tar.gz /var/games/minecraft/java
root@b260116662e0:/ cd /var/games/minecraft/java
root@b260116662e0:/var/games/minecraft/java tar -xf jdk-16.0.1_linux-x64_bin.tar.gz 
root@b260116662e0:/var/games/minecraft/java ls
jdk-16.0.1     jdk-16.0.1_linux-x64_bin.tar.gz 

and during step 5, instead of being

it would be

java_binary=/var/games/minecraft/java/jdk-16.0.1/bin/java
1 Like

Indeed! My mistake; updated it to match what you mentioned, thanks for the double-checking my work~

1 Like