Issue
I am trying to containerize my Spring application with Docker. However, Docker cannot find my jar file. My Dockerfile:
FROM adoptopenjdk:16-jre-hotspot
RUN mkdir -p /app
WORKDIR /app
ARG JAR_FILE=*.jar
COPY ${JAR_FILE} rtv-1.jar /app
ENTRYPOINT ["java", "-jar", "/rtv-1.jar"]
My docker-compose.yml
version: '2'
services:
app:
image: 'docker-spring-boot-postgres:latest'
build:
context: .
container_name: app
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
- SPRING_DATASOURCE_USERNAME=compose-postgres
- SPRING_DATASOURCE_PASSWORD=compose-postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
volumes:
- absolutepathtothedircontaining "rtv-1":/app
db:
image: 'postgres:13.1-alpine'
container_name: db
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=compose-postgres
When I run docker-compose up I am still having the same error.
Any idea what is causing this issue?
Many thanks in advance
Solution
Please make sure, rtv-1.jar
file and Dockerfile
file are in the same folder.
Just copy rtv-1.jar
file to /app
folder.
COPY rtv-1.jar /app
its a wrong path:
Change it : ENTRYPOINT ["java", "-jar", "/rtv-1.jar"]
To : ENTRYPOINT ["java", "-jar", "rtv-1.jar"]
Or : ENTRYPOINT ["java", "-jar", "/app/rtv-1.jar"]
Answered By - Thanh Nguyen Van