2

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?

1
  • You haven't COPYed any content into your image, so Maven can't find the pom.xml file or any of your source code.
    – David Maze
    Jul 11, 2020 at 14:00

1 Answer 1

1

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.

2
  • After building docker image successfully, Run docker run <image_name>:tag following error would show: [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Jul 12, 2020 at 6:01
  • But the error you posted above shows that it's happening on step 2/3 which the mvn clean install step. I don't understand what you image is build successfully. Jul 12, 2020 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.