我正在尝试为我的spring-boot应用程序构建一个docker映像。 这是我的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"]
这是我的pom.xml文件,其中有io.fabric8插件:
`<?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>`.
当我尝试使用mvn package docker:build
构建docker映像时
我遇到错误:
无法执行目标io.fabric8:docker-maven-plugin:0.15.3:build (default-cli)在项目detailsapp上:执行目标的default-cli io.fabric8:docker-maven-plugin:0.15.3:build失败。 NullPointerException-> [帮助1]
有人可以提供解决方案吗,将不胜感激。 谢谢!
答案 0 :(得分:0)
这对我有用,可以构建docker映像并将其推送到docker hub,我不使用docker文件,而是通过Fabric创建它:
mvn clean install fabric8:build fabric8:push
我的pom看起来像这样:
<?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>