Reputation: 73
The below image couldn't be built because this image doesn't support shell form and supports only exec form, hence RUN as well as ENTRYPOINT support only vector form. Please suggest how to build the exact image as it is important to use this one.
FROM gcr.io/distroless/java:8
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /aaa/bbb/*
COPY target/${JAR_FILE} /xyz/yy.jar
ENTRYPOINT exec java $JAVA_OPTS -Djdk.tls.client.protocols="tls" -jar /xyz/yy.jar $0 $@
Also, When I try to specify RUN in vector form I get "exec: "apt-get" executable file not found in $PATH".
Upvotes: 0
Views: 834
Reputation: 2876
The exec ... $@
use seems a bit strange here...
ENTRYPOINT
is configuring your container to run as the executable, allowing your CMD
to provide default arguments to your executable, so the use of $0 $@
is 100% unnecessary.
Although I don't have any Java lying around to use, something like this should in theory work:
ARG JAR_FILE=build/*.jar
FROM gcr.io/distroless/java:8
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -qqy --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*```
COPY ${JAR_FILE} app.jar
ENV JAVA_OPTS="-Djdk.tls.client.protocols=tls"
ENTRYPOINT ["java", "-jar", "$JAVA_OPTS", "-jar", "app.jar"]
# By providing an entrypoint above, your CMD can optionally define any default
# arguments you might want to fallback to.
# CMD [ "--java", "--things" ]
The preferred usage however is to leverage your CMD
as the exec
and not include the ENTRYPOINT
in this type of use at all. Then, your entirely CMD
is customizable and you can remove the need for $JAVA_OPTS
:
ARG JAR_FILE=build/*.jar
FROM gcr.io/distroless/java:8
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -qqy --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*```
COPY ${JAR_FILE} app.jar
ENV JAVA_OPTS="-Djdk.tls.client.protocols=tls"
# By providing an entrypoint above, your CMD can optionally define any default
# arguments you might want to fallback to.
CMD ["java", "-jar", "$JAVA_OPTS", "-jar", "app.jar"]
If you did keep it the same, an additional change I made was moving your JAVA_OPTS
to an ARG
. The simple rule of thumb here is: ARG
is for build, ENV
is for runtime.
Warning: The above over simplification is overly simple.
But, this would change your build command (if you needed to overwrite the JAR_FILE
to this:
docker build -t jarjar/binks --build-arg JAR_FILE=another/file.jar .
And you would run it quite similarly:
JAVA_OPTS="-Djdk.tls.client.protocols='TLSv1,TLSv1.1' -Xms#G -Xmx#G" &&
docker run jarjar/binksjarjar/binks --args=here
I do encourage you to read further into both CMD
and `ENTRYPOINT to understand the pros/cons of using them together/separately.
Unfortunately I wasn't actually able to run any of these before posting my answer, and reviewing the comment from koorkevani, that's 100% more the issue you're going to be running into over my feedback.
Take his answer and let us know if you run into any other issues :)
Upvotes: 1