I'm trying to run Spring application by docker compose up and then I have error
ERROR [2/2] COPY target/*.jar app.jar
My thoughts are that the path is wrong in Dockerfile to jar file.
docker-compose.yml
version: '3.8'
services:
app-backend:
image: my-app
ports:
- "8010:8080"
build:
context: .
dockerfile: "Dockerfile"
Dockerfile
FROM openjdk:11-jdk
EXPOSE 8010
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} my-app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "/my-app.jar"]
And here is a structure of my project
So my question is: what is wrong with this path or what causes this error?
I guess you can try using the Makefile to automate some work for you?
here is a sample implementation:
POM_VERSION = $(shell mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
build:
cp target/app-$(POM_VERSION).jar src/main/Docker/dev/my-app.jar
docker-build: build
cd src/main/Docker/dev && docker-compose up
place this Makefile in root dir.
and Dockerfile should be:
FROM openjdk:11-jdk
EXPOSE 8010
ADD my-app.jar my-app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "/my-app.jar"]
now simply run: make docker-build
make sure that the makefile has tabular spaces
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.