I'm trying to build a dockerfile. I earlier tried using hard coded paths for my project and the output was fine. However, as soon as I started using a variable, the java code stopped executing.
Dockerfile
FROM java:7
EXPOSE 7100
ARG version
ENV version=$version
RUN echo $version
RUN mkdir -p /cacheDir/services/live/prediction/p7100/$version/logs
RUN ls -tlr /cacheDir/services/live/prediction/p7100/
RUN mkdir -p /cacheDir/services/releases/prediction/p7100/$version/
RUN mkdir -p /cacheDir/services/predictionmodel
ADD target/predictionDependencies/star /cacheDir/services/predictionmodel/ #star here is the operator (*), it was being interpret as comments by this stackoverflow editor.
ADD /target/prediction-0.0.13-SNAPSHOT.jar /cacheDir/services/releases/prediction/p7100/$version/prediction-0.0.13-SNAPSHOT.jar
ADD /target/instance.properties /cacheDir/services/releases/prediction/p7100/$version/instance.properties
ADD /target/logback.xml /cacheDir/services/releases/prediction/p7100/$version/logback.xml
RUN ls -ltr /cacheDir/services/live/prediction/p7100/$version/
RUN ls -ltr /cacheDir/services/releases/prediction/p7100/$version/
RUN ls -ltr /cacheDir/services/predictionmodel
ENTRYPOINT java -server -Xmx2g -Xloggc:/cacheDir/services/live/prediction/p7100/$version/logs/gc.log -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/cacheDir/services/live/prediction/p7100/$version/oom.dump -Dlogback.configurationFile=/cacheDir/services/releases/prediction/p7100/$version/logback.xml -Dlog.home=/cacheDir/services/live/prediction/p7100/$version/logs -Dlogback.debug=true -Dbroker.l^Ct=sv-kafka6.pv.sv.nextag.com:9092,sv-kafka7.pv.sv.nextag.com:9092,sv-kafka8.pv.sv.nextag.com:9092,sv-kafka9.pv.sv.nextag.com:9092 -jar /cacheDir/services/releases/prediction/p7100/$version/prediction-0.0.13-SNAPSHOT.jar 7100 /cacheDir/services/releases/prediction/p7100/$version/instance.properties /com/wizecommerce/services/qa &
Command used to build the image.
docker build --build-arg version=0.0.14-SNAPSHOT -t prediction:0.0.14-SNAPSHOT .
The image seems to be successful. However, when I run the command, the container just exits on it own. Run command used:
docker run -p 7100:7100 -v ~/PredictionVolume/logs/:/cacheDir/services/live/prediction/p7100/0.0.14-SNAPSHOT/logs/ -t prediction:0.0.14-SNAPSHOT
And when tried to view the running container, it wasn't running.
I tried working with these tow solutions which I have found but none seems to work.
How do I use Docker environment variable in ENTRYPOINT array?
Other solution was that I used the replaced the following ENTRYPOINT command with this one.
ENTRYPOINT ["sh","-c","java","-server","-Xmx2g","-Xloggc:/cacheDir/services/live/prediction/p7100/${version}/logs/gc.log","-verbose:gc","-XX:+PrintGCDateStamps","-XX:+PrintGCDetails","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/cacheDir/services/live/prediction/p7100/${version}/oom.dump","-Dlogback.configurationFile=/cacheDir/services/releases/prediction/p7100/${version}/logback.xml","-Dlog.home=/cacheDir/services/live/prediction/p7100/${version}/logs","-Dlogback.debug=true","-Dbroker.l^Ct=sv-kafka6.pv.sv.nextag.com:9092,sv-kafka7.pv.sv.nextag.com:9092,sv-kafka8.pv.sv.nextag.com:9092,sv-kafka9.pv.sv.nextag.com:9092","-jar","/cacheDir/services/releases/prediction/p7100/${version}/prediction-0.0.13-SNAPSHOT.jar","7100","/cacheDir/services/releases/prediction/p7100/${version}/instance.properties","/com/wizecommerce/services/qa","&"]
But with this command the output comes like, if you type java on the terminal showing all the options available to use will be shown on the screen(terminal).
Can anyone please suggest a way out? Thanks!!!