编辑pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--docker 部署-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>${project.groupId}/${project.artifactId}</imageName>
<imageTags>
<!--镜像标签-->
<imageTag>latest</imageTag>
</imageTags>
<forceTags>true</forceTags>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
在 \src\main\docker 下创建Dockerfile
内容如下
FROM java:8
VOLUME /tmp
ADD admin-service-80-0.0.1-SNAPSHOT.jar admin-service-80.jar
RUN bash -c 'touch /admin-service-80.jar'
EXPOSE 80
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/admin-service-80.jar"]
选择 maven docker 构建
打印
"C:\Program Files\Java\jdk1.8.0_202\bin\java.exe" -Dmaven.multiModuleProjectDirectory=E:\oopdd\v2\pay_core_gateway\paycoregateway\admin-service-80 "-Dmaven.home=D:\software\IntelliJ IDEA 2019.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\software\IntelliJ IDEA 2019.2\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\software\IntelliJ IDEA 2019.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\software\IntelliJ IDEA 2019.2\lib\idea_rt.jar=58959:D:\software\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\software\IntelliJ IDEA 2019.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version2019.2 com.spotify:docker-maven-plugin:0.4.13:build
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.zfl:admin-service-80 >----------------------
[INFO] Building admin-service-80 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- docker-maven-plugin:0.4.13:build (default-cli) @ admin-service-80 ---
[INFO] Copying E:\oopdd\v2\pay_core_gateway\paycoregateway\admin-service-80\target\admin-service-80-0.0.1-SNAPSHOT.jar -> E:\oopdd\v2\pay_core_gateway\paycoregateway\admin-service-80\target\docker\admin-service-80-0.0.1-SNAPSHOT.jar
[INFO] Copying E:\oopdd\v2\pay_core_gateway\paycoregateway\admin-service-80\src\main\docker\Dockerfile -> E:\oopdd\v2\pay_core_gateway\paycoregateway\admin-service-80\target\docker\Dockerfile
[INFO] Building image com.zfl/admin-service-80
Step 1/6 : FROM java:8
---> d23bdf5b1b1b
Step 2/6 : VOLUME /tmp
---> Using cache
---> c0dab636f6d9
Step 3/6 : ADD admin-service-80-0.0.1-SNAPSHOT.jar admin-service-80.jar
---> b93047986564
Step 4/6 : RUN bash -c 'touch /admin-service-80.jar'
---> Running in 6349c6b6760c
Removing intermediate container 6349c6b6760c
---> a7e726592a22
Step 5/6 : EXPOSE 80
---> Running in eb73dbd4aafa
Removing intermediate container eb73dbd4aafa
---> 9fe9973824a5
Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/admin-service-80.jar"]
---> Running in d9d7bcfad8d8
Removing intermediate container d9d7bcfad8d8
---> 316713a10e56
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 316713a10e56
Successfully tagged com.zfl/admin-service-80:latest
[INFO] Built com.zfl/admin-service-80
[INFO] Tagging com.zfl/admin-service-80 with latest
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.018 s
[INFO] Finished at: 2020-01-09T13:07:16+08:00
[INFO] ------------------------------------------------------------------------
查看镜像
已经 多出来了一个镜像