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.
Edit: Follow up
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 :)
apt-getdoesn't exist ingcr.io/distroless/java:8. In fact, the only useful executables that do arejavaandopenssl- it doesn't even containls,cat, or evensh. Either directlyCOPYthe executables you need, or consider using another base image.