仓库源文.md),站点原文)


layout: post title: "Docker实战(三)" categories: Docker tags: Docker maven

author: 张乘辉

在 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-deploy

查看 docker 镜像列表:

docker-deploy

运行 docker 镜像:

docker-deploy

访问 http://localhost:8080/,返回以下结果:

hello-springboot

获取 Demo 源码:

docker-deploy-tutorial