I am creating a docker image using below configuration. Once image is ready i want to pass JAVA_OPTS to my docker container, so it can be passed to my spring boot application. Whenever i try to bring up the container i am getting "runtime create failed: container_linux.go:348: starting container process caused "exec: \"java $JAVA_OPTS\": executable file not found in $PATH": unknown" error. Am i missing something ? Any help is really appreciated
Dockerfile
FROM openjdk:8-jdk-alpine
LABEL maintainer="[email protected]"
# Add a volume pointing to /tmp
VOLUME /tmp
# Make port 8080 available to the world outside this container
EXPOSE 8080
# The application's jar file
ARG JAR_FILE=target/my.jar
# Add the application's jar to the container
ADD ${JAR_FILE} my.jar
ENV JAVA_OPTS=""
# Run the jar file
ENTRYPOINT ["java $JAVA_OPTS","-Djava.security.egd=file:/dev/./urandom","-jar","/my.jar"]
docker-compose
version: '2.1'
services:
service1:
hostname: test
domainname: mydomain.com
image: myimage:latest
container_name: test-container
environment:
- JAVA_OPTS=-Dapp.clients.scheme=http -Dapp.clients.port=9096 -Dserver.port=8082
ports:
- "8082:8082"
You shouldn't use java $JAVA_OPTS
with ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS"]
The main problem with it is that with this approach you application won't receive the sigterm so in case of graceful shutdown it won't work for you (you will find more about the problem here if you are not aware about that)
If you want customize the java opts on docker environments use JAVA_TOOL_OPTIONS
environment property (https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html) and ENTRYPOINT ["java", ...]
With this property you can declare your expected options even in Dockerfile like:
ENV JAVA_TOOL_OPTIONS "-XX:MaxRAMPercentage=80"
And you can easily override it later with external provided docker or kubernetes property.
The JAVA_TOOL_OPTIONS
is used by the jib
project - more here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With