layout: post title: "Docker实战(三)" categories: Docker tags: Docker maven
在 maven pom.xml 中加入 docker-maven-plugin 插件:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<!-- objcoding/docker-maven-deploy打包后的名称,0.0.2镜像 TAG -->
<imageName>objcoding/docker-maven-deploy:0.0.2</imageName>
<!-- Dockerfile 所在路径 --><dockerDirectory>${project.basedir}/src/main/resources/docker</dockerDirectory>
<resources>
<resource>
<!-- target 所在路径 -->
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<!-- 打包后的 springboot jar 包文件名称 -->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<!-- docker仓库 -->
<!-- <serverId>my-docker-repository</serverId> -->
</configuration>
</plugin>
在 src/main/resources/docker/ 中添加 Dockerfile:
From java:8
MAINTAINER zhangchenghui zhangchenghui.dev@gmail.com
ADD docker-maven-sample-1.0-SNAPSHOT.jar /app.jar
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "app.jar" ]
在项目根目录下执行一下命令:
mvn clean install docker:build
出现以下编译后的信息:
查看 docker 镜像列表:
运行 docker 镜像:
访问 http://localhost:8080/,返回以下结果:
获取 Demo 源码: