I have Java app and want to generate docker image, I have shell script like this:
#!/bin/sh java -version export APPLICATION_DIR=$PWD for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar` do export CLASSPATH=$rJarFile:$CLASSPATH done export CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH java -Xverify:none -Xmx2048m -Djava.awt.headless=true -DFI_IS_CONFIGSER=N -DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1 -DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties -DFEBA_SYS_PATH=${APPLICATION_DIR}/data
And I try to convert it into Dockerfile like this
# FROM openjdk:8 FROM openjdk:11 RUN javac -version # Create app directory WORKDIR /usr/src/app # Bundle app source COPY . . ENV APPLICATION_DIR=/usr/src/app RUN echo $APPLICATION_DIR RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export CLASSPATH=$rJarFile:$CLASSPATH; done RUN echo $CLASSPATH ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH # Run app ENTRYPOINT ["java", "-Xverify:none", "-Xmx2048m", "-Djava.awt.headless=true", "-DFI_IS_CONFIGSER=N", "-DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1", "-DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties", "-DFEBA_SYS_PATH=${APPLICATION_DIR}/data"]
It can be generated, but there’s an error when I try to run it like this:
Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: setenv: invalid argument: unknown
I’ve also changed this script RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export
into this RUN for rJarFile in ls ${APPLICATION_DIR}/lib/*.jar; do export CLASSPATH=$rJarFile:$CLASSPATH; done
, but none of them working. I don’t want to make Dockerfile execute the script. Below is logs when i generate and run it.
Advertisement
Answer
You cannot update the classpath as you do with:
ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
instead you can do
ENV CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
Also – please consider moving the script into a separate shell script and adding into the container. This would greatly simplify the Dockerfile, for example:
# FROM openjdk:8 FROM openjdk:11 RUN javac -version # Create app directory WORKDIR /usr/src/app # Bundle app source COPY . . ENV APPLICATION_DIR=/usr/src/app RUN echo $APPLICATION_DIR ENTRYPOINT ["/usr/src/app/start_java.sh"]
and keep your existing script inside start_java.sh