I created the following Dockerfile in my project to containerize Spring app
FROM java:8
EXPOSE 8080
VOLUME /tmp
ADD ./spring-boot-app.jar /app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]
Whether or not I try providing the complete project path of jar file in ADD ./spring-boot-app.jar /app/app.jar, it still results in the below error anyway-
Execution failed for task ':buildDocker'. Docker execution failed Command line [docker build -t spring-boot-app:latest /Users/sh/temp/service/build/docker] returned: ADD failed: stat /var/lib/docker/tmp/docker-builder448261255/spring-boot-app.jar: no such file or directory
Additionally, if there is an easier way or alternative solution , appreciate the suggestions.
Based on comments, I tried this in Dockerfile and was able to get pass the previous erro:
FROM openjdk:8-jre-alpine
ADD build/libs/*.jar app.jar
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
But when running command docker-compose up , it isn't linking spring boot app container with mysql container and giving communication link failure error. It's possibly because of Dockerfile ENTRYPOINT. Here is docker-compose.yml :
version: '3'
services:
demo-mysql:
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: smthing
MYSQL_DATABASE: smthing
MYSQL_USER: smthing
MYSQL_PASSWORD: smthing
spring-boot-docker-webapp:
build:
context: .
dockerfile: Dockerfile
depends_on:
- demo-mysql
ports:
- 8080:8080
environment:
DATABASE_HOST: demo-mysql
DATABASE_USER: smthing
DATABASE_PASSWORD: smthing
DATABASE_NAME: smthing
DATABASE_PORT: 3306