Docker Community Forums

Share and learn in the Docker community.

Java error when using cpuset-cpus

Hello,

i am trying to run a container using the following command:

sudo -S -k docker run --memory=“2048m” --kernel-memory=“24m” --cpuset-cpus=“11” --cpu-shares 512 --name c_1000 --user root -p 25565:25565/tcp --workdir /container --rm c_1000 /bin/bash -c “wget -q -O /container/server.jar https://papermc.io/api/v1/paper/1.16.1/135/download; echo “eula=true” > /container/eula.txt; java -Xms256m -Xmx1024m -DIReallyKnowWhatIAmDoingISwear=true -jar server.jar;”

But every time i get a error. Does anyone know why this happens?

Greetings

OS:
Ubuntu 20.04 LTS

Docker version:
19.03.12

DockerFile

FROM openjdk:8-jdk-alpine
RUN adduser -H -u 1040 c_1000 container_group; addgroup -g 1001 container_group; echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories; apk add --update wget; apk add screen; apk add bash; rm -rf /var/cache/apk/;

Java error:

[21:18:07 ERROR]: Encountered an unexpected exception
java.lang.ExceptionInInitializerError: null
at net.minecraft.server.v1_16_R1.ServerConnection.lambda$static$1(ServerConnection.java:36) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.LazyInitVar.a(SourceFile:16) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.ServerConnection.a(ServerConnection.java:92) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.DedicatedServer.init(DedicatedServer.java:198) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:941) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$a$0(MinecraftServer.java:177) ~[patched_1.16.1.jar:git-Paper-135]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]
Caused by: java.lang.IllegalArgumentException: availableProcessors: 0 (expected: > 0)
at io.netty.util.internal.ObjectUtil.checkPositive(ObjectUtil.java:44) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.availableProcessors(NettyRuntime.java:70) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime.availableProcessors(NettyRuntime.java:98) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.channel.MultithreadEventLoopGroup.(MultithreadEventLoopGroup.java:41) ~[patched_1.16.1.jar:git-Paper-135]
… 7 more
[21:18:07 ERROR]: Cause of unexpected exception was
java.lang.IllegalArgumentException: availableProcessors: 0 (expected: > 0)
at io.netty.util.internal.ObjectUtil.checkPositive(ObjectUtil.java:44) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.availableProcessors(NettyRuntime.java:70) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.util.NettyRuntime.availableProcessors(NettyRuntime.java:98) ~[patched_1.16.1.jar:git-Paper-135]
at io.netty.channel.MultithreadEventLoopGroup.(MultithreadEventLoopGroup.java:41) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.ServerConnection.lambda$static$1(ServerConnection.java:36) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.LazyInitVar.a(SourceFile:16) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.ServerConnection.a(ServerConnection.java:92) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.DedicatedServer.init(DedicatedServer.java:198) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:941) ~[patched_1.16.1.jar:git-Paper-135]
at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$a$0(MinecraftServer.java:177) ~[patched_1.16.1.jar:git-Paper-135]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]

In addition to Runtime.availableProcessors(), it appears Hotspot has also updated JVMTI API GetAvailableProcessors() to return same value as Runtime.availableProcessors().
I created a docker image using build 10-ea+40 and tested the output of Runtime.availableProcessors() and GetAvailableProcessors():

Using cpusets:

docker run --rm --cpuset-cpus=0-3 --volume=/home/ashu/jvmtiTest:/jvmtiTest --entrypoint=/java/jdk-10/bin/java openjdk:jdk10_40 -agentpath:/jvmtiTest/libagent.so -cp /jvmtiTest ProcessorTest

jvmtiGetAvailableProcessors returned: 4
Runtime.availableProcessors: 4

Using cpu quota:

docker run --rm --cpuset-cpus=0-3 --cpus=2 --volume=/home/ashu/jvmtiTest:/jvmtiTest --entrypoint=/java/jdk-10/bin/java openjdk:jdk10_40 -agentpath:/jvmtiTest/libagent.so -cp /jvmtiTest ProcessorTest

jvmtiGetAvailableProcessors returned: 2
Runtime.availableProcessors: 2