Reputation: 412
Facing problems in docker file (spring boot maven project). When running docker file, it gives an error "The command '/bin/sh -c mvn -f pom.xml clean package' returned a non-zero code: 1". However if I directly execute the command 'mvn -f pom.xml clean package', I do not get any error.
FROM maven:3.6.1-jdk-8-slim AS build
RUN mkdir -p /workspace
WORKDIR /workspace
COPY pom.xml /workspace
COPY src /workspace/src
RUN mvn -f pom.xml clean package
FROM openjdk:8-alpine
COPY --from=build /workspace/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
Please help on the same.
Upvotes: 0
Views: 1259
Reputation: 939
You can use experimental feature cache to speed up building process
# syntax=docker/dockerfile:1.0-experimental
you dont need to run mkdir
RUN mkdir -p /workspace
just workdir is enought
WORKDIR /workspace
you can copy folder by
COPY . .
and add .dockerignore file from preventing not build related files and folders
RUN --mount=type=cache,target=/root/.m2/repository mvn -e -B clean package -
Dmaven.test.skip=true
change
ENTRYPOINT ["java","-jar","app.jar"]
to
CMD ["java","-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
maven output will be helpfull to detect what exactly is wrong.
Upvotes: 1