8

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?

Community
  • 1
  • 1
deep
  • 1,586
  • 1
  • 18
  • 29

2 Answers2

8

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"]
mpetruska
  • 633
  • 3
  • 6
6

This post suggests using explicit exec in ENTRYPOINT:

ENTRYPOINT exec java $JAVA_OPTS