1
votes

I am trying to build a docker image for my spring-boot application. This is my Dockerfile:

FROM ubuntu
ENV JAVA_VERSION 8u31
ENV BUILD_VERSION b13
# Upgrading system
RUN apt-get -y upgrade
RUN apt-get -y install wget
# Downloading & Config Java 8
RUN wget --no-cookies --no-check-certificate --header "Cookie: 
oraclelicense=accept-securebackup-cookie" 
 "http://download.oracle.com/otn- 
 pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/jdk-$JAVA_VERSION-linux- 
x64.rpm" -O /tmp/jdk-8-linux-x64.rpm
RUN apt-get -y install /tmp/jdk-8-linux-x64.rpm

RUN alternatives -- install  /usr/lib/jvm/java-8-oracle/jre/bin/java          
1081      
RUN alternatives --install /usr/lib/jvm/java-8-openjdk- 
amd64/jre/bin/java   1081      
 RUN alternatives --install /usr/lib/jvm/java-8-oracle/jre/bin/java          
1081     


  EXPOSE 8089
  #install Spring Boot artifact
    VOLUME /tmp
    ADD /maven/sfg-thymeleaf-course-0.0.1-SNAPSHOT.jar sfg-thymeleaf- 
  course.jar
   RUN sh -c 'touch /sfg-thymeleaf-course.jar'
     ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","- 
   jar","/sfg-thymeleaf-course.jar"]

This is my pom.xml file where i have my io.fabric8 plugin there:

            `<?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 
   http://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.1.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.uipurpose</groupId>
<artifactId>detailsapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>detailsapp</name>
<description>Demo project for integrating with Angular</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>com.microsoft.sqlserver</groupId>-->
        <!--<artifactId>mssql-jdbc</artifactId>-->
        <!--<scope>runtime</scope>-->
    <!--</dependency>-->

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
       <plugin>
     <groupId>io.fabric8</groupId>
       <artifactId>docker-maven-plugin</artifactId>
      <version>0.15.3</version>
       <configuration>
        <dockerHost>http://127.0.0.1:2375</dockerHost>
           <verbose>true</verbose>
          <images>
          <image>
        <name>nisharunnisa/sample-spring-boot-app</name>
         <build>
           <dockerFile>Dockerfile</dockerFile>
          <assembly>
        <descriptorRef>artifact</descriptorRef>
       </assembly>
        </build>
       </image>
       </images>
     </configuration>
     </plugin>
    </plugins>
   </build>

    </project>`.

When I am trying to build a docker image using mvn package docker:build i am getting an error :

Failed to execute goal io.fabric8:docker-maven-plugin:0.15.3:build (default-cli) on project detailsapp: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.15.3:build failed. NullPointerException -> [Help 1]

Can Someone help with the solution, It will be grate. Thank you!

1

1 Answers

1
votes

This works for me, to build docker image and push to docker hub, I don't use a docker file, fabric creates it:

mvn clean install fabric8:build fabric8:push

My pom looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.gregclinker</groupId>
    <artifactId>boot-docker</artifactId>
    <version>1.0.4</version>
    <packaging>jar</packaging>

    <name>Boot Docker</name>
    <description>Spring Boot and Docker</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
        <relativePath />
    </parent>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>fabric8-maven-plugin</artifactId>
                <version>3.5.41</version>
            </plugin>

        </plugins>
    </build>

</project>