springboot
项目pom.xml
文件
<properties>
<java.version>1.8java.version>
<maven.compiler.source>8maven.compiler.source>
<maven.compiler.target>8maven.compiler.target>
<docker.image.prefix>demo-dockerdocker.image.prefix>
<skipTests>trueskipTests>
properties>
<build>
<finalName>docker-cloud-demofinalName>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
<configuration>
<fork>truefork>
<addResources>trueaddResources>
configuration>
plugin>
<plugin>
<groupId>com.spotifygroupId>
<artifactId>dockerfile-maven-pluginartifactId>
<version>1.4.10version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jarJAR_FILE>
buildArgs>
configuration>
plugin>
plugins>
build>
Dockerfile
文件Dockerfile
文件配置FROM adoptopenjdk/openjdk8:jre8u-nightly
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
controller
mvn clean package dockerfile:build
注意
: 执行项目生成镜像,默认连接的是本机docker
服务的2375
端口,如果本机未开通端口需要开通才能正常打包成镜像,如需要远程打包,需要添加环境变量DOCKER_HOST
,并指向远程服务的2375
端口.
DOCKER_HOST tcp://192.168.2.104:2375