scaladockerdockerfileammonite

How to pass Java_opts before an executable to entrypoint in dockerfile?


I am running a scala script with ammonite. I need to pass JAVA_OPTS to limit the memory consumed by ammonite. According to the ammonite docs, I can do it by doing
JAVA_OPTS='-Xmx<limit>' amm <scala script>

Now I want to run this script inside a docker container, which I am doing with like this:

FROM <open jdk image>
WORKDIR /opt/docker
ADD scm-source.json /
ADD --chown=daemon:daemon deps/amm /opt/docker
RUN mkdir amm_home && chown daemon:daemon amm_home
RUN mkdir data && chown daemon:daemon data
ADD --chown=daemon:daemon UserPrefExporter.sc /opt/docker
USER daemon
ENTRYPOINT ["./amm", "-h", "amm_home", "UserPrefExporter.sc"]

This runs fine and runs the script. The problem lies in passing the JAVA_OPTS to amm.
ENTRYPOINT requires first parameter to be the executable but I want to have JAVA_OPTS before amm.

How to achieve this?


Solution

  • You can declare environment variables with ENV:

    ...
    ADD --chown=daemon:daemon UserPrefExporter.sc /opt/docker
    USER daemon
    ENV JAVA_OPTS="-Xmx<limit>"
    ENTRYPOINT ["./amm", "-h", "amm_home", "UserPrefExporter.sc"]