1

I need to create a docker file and build docker image for maven project with including the setting.xml from conf/settigs.xml (For remote repository configuration)

So I'm trying to learn how to use maven, spring-boot and docker to create a web-application.

I tried using maven plugins. I included in pom.xml file.

<plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.5</version>
            <configuration>
                <repository>${project.artifactId}</repository> <!-- ${project.artifactId} is a good choice -->
                <tag>${project.version}</tag>
                <baseImage>java</baseImage>
                <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>


            </configuration>
        </plugin>


        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>javax.activation</groupId>
                    <artifactId>activation</artifactId>
                    <version>1.1.1</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>

Docker file

    #
# Build stage
#
FROM maven:3.6.3-0penjdk:11-jdk AS build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package

#
# Package stage
#
FROM openjdk:11-jre-slim
COPY --from=build /home/app/target/demo-0.0.1-SNAPSHOT.jar /usr/local/lib/demo.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/demo.jar"]

But I am facing issues. While running the command mvn clean install dockerfile:build

Docker image are creating without name and tag. I assume it will take the values from repository and tag elements from configuration of plugin. But not sure.

Image will be built without a name

I am using java 11 and maven 3.6.3 version.

Anyone please suggest a best way for creating a docker file for maven project with referring the remote repository configured conf/settings.xml.

Thanks in Advance

Debugger
  • 690
  • 1
  • 18
  • 41
  • The spring boot documentation has a fully worked example with docker https://spring.io/guides/gs/spring-boot-docker/ – jamesioppolo Feb 20 '20 at 02:32

0 Answers0