Issue
I am trying to run a Maven + Spring project in a docker file. As a Maven/Spring newbie, I am not sure why the executable doesn't run in a Docker container. The same build works after I "Clean and Build" in NetBeans IDE and run the java file manually from the IDE.
The error I get when trying to run the same in Docker via docker-compose build
and docker-compose run
is:
No goals have been specified for this build.
(Full error below, together with POM
, dockerfile
and docker-compose
file)
I have copied the built .jar file (myapp-1.0.jar) into the mymaven folder.
What do I need to do to be able to build and run the executable programme in a Docker container?
Any help here is appreciated :)
Dockerfile:
FROM maven:3.6.3 AS maven
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN mvn install
FROM adoptopenjdk/openjdk11:alpine-jre
WORKDIR /opt/app
COPY --from=maven mymaven/myapp-1.0.jar /opt/app/
ENTRYPOINT ["java","-jar","myapp-1.0.jar"]
docker-compose.yaml:
mymaven:
image: maven
depends_on:
- server1
- server2
networks:
- mynetwork
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>mymaven</artifactId>
<version>1.0</version>
<name>myapp</name>
<description>My App</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Error:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.051 s
[INFO] Finished at: 2022-07-24T10:58:03Z
[INFO] ------------------------------------------------------------------------
[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>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
Solution
The docker-compose file was pointing to the standard Docker image and not the build folder with the dockerfile.
mymaven:
#image: maven (wrong)
build: mymaven
depends_on:
- server1
- server2
networks:
- mynetwork
Answered By - D. Caan
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)