Get memory limit in docker file?

2019-06-24 15:17发布

问题:

Is it possible to get the max memory of a docker container at runtime?

What I want to achieve is:

docker run --memory "100m"

and access the max memory in the docker file:

ENTRYPOINT ["java", "-Xmx$memory", "-jar", "helloworld.jar"]

回答1:

Don't think you can specify memory constraints in the Dockerfile yet. So the way to do it is to override your entrypoint at the command line:

$ docker run -i -t --memory "100m" --entrypoint "java -Xmx`cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -jar helloworld.jar" example/java-hello


标签: java docker