I have a spring boot project and trying to build the project with a Docker file on OpenShift V3.
The problem is that I only have my source code in my git repo; no target directory or jar file. My Dockerfile is not able to get the final artifact (packaging the application to a jar).
Following is my docker file contents
FROM bdf/api-java8-maven-exp-srv-builder
EXPOSE 8080
VOLUME /tmp
WORKDIR /code
ADD pom.xml /code/pom.xml
ADD Dockerfile /code
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
ADD src /code/src
RUN ["mvn", "package"]
ADD /code/target/springbootdemo-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container","-jar","/app.jar"]
All commands are working properly except ADD /code/target/springbootdemo-0.0.1-SNAPSHOT.jar app.jar
Command: RUN ["mvn", "package"] - It execute successfully and shows that jar file is created on console at location /target/springbootdemo-0.0.1-SNAPSHOT.jar
*Projct Folder Structure
Project Name-
- src Folder
- mvn/wrapper
- Docker File
- Pom.XML
- mvnw
- mvnwc
Following DockerFile works for me
FROM bfg/api-java8-maven-exp-srv-builder
EXPOSE 8080
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD ADD . /usr/src/app
ONBUILD RUN mvn install
ONBUILD ADD /usr/src/app/target/springbootdemo-0.0.1-SNAPSHOT.jar app.jar
CMD ["java","-jar","/app.jar"]