简体   繁体   中英

How write correctly a Docker file to build war file and run spring-boot maven project?

Dockerfile:

FROM maven:3.6.3-jdk-11

RUN mvn clean install

RUN mvn spring-boot:run

Then run,

$ docker image build -t  hello-world .

when i run above command then following error would occurred.

Sending build context to Docker daemon 206.6MB

Step 1/3: FROM maven:3.6.3-jdk-11 ---> 918519009705

Step 2/3: RUN mvn clean install ---> Running in d915d2ac25e7

[INFO] Scanning for projects...

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 0.153 s

[INFO] Finished at: 2020-07-11T12:33:30Z

[INFO] ------------------------------------------------------------------------

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/). Please verify you invoked Maven from the correct directory. -> [Help 1]

[ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException

Now, Can you explain a proper way to build(.war file) and run a maven project using docker image for windows?

You need to copy the pom.xml as well as the source code so that they are available within the container for building. Then you may do the run step.

Example:

### BUILD image
FROM maven:3-jdk-11 as builder
# create app folder for sources
RUN mkdir -p /build
WORKDIR /build
COPY pom.xml /build
#Download all required dependencies into one layer
RUN mvn -B dependency:resolve dependency:resolve-plugins
#Copy source code
COPY src /build/src
# Build application
RUN mvn package

Code snippet from https://dzone.com/articles/spring-boot-run-and-build-in-docker Visit for full explanation.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM