dockerfile-maven plugin自动镜像制作并发布

环境准备:win10+docker
1.打开hyper-v
3.切换到docker的linux环境:右键桌面右下角小船图标
4.暴露2375端口
 
用户认证信息配置:
<configuration>
<repository>docker-repo.example.com:8080/organization/image</repository>
<tag>latest</tag>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
</configuration>

setting.xml添加远程仓库信息

<servers>
<server>
<id>docker-repo.example.com:8080</id>
<username>me</username>
<password>mypassword</password>
</server>
</servers>

pom.xml配置

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
//上下文路径配置,此处设置为项目根路径
<contextDirectory>${project.basedir}</contextDirectory>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<repository>${registryUrl}/hush/${project.build.finalName}</repository>
<tag>${imageVersion}</tag>
//作为Dockerfile文件传入
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>

Dockerfile文件编写(放置在项目根路径)

FROM registry.cn-hangzhou.aliyuncs.com/hush/basecontainer:20180929

#添加本地jar包
RUN mkdir -p /home/admin/app/
RUN mkdir -p /home/admin/tomcat/
ENV CATALINA_HOME /home/admin/tomcat/
#
ARG JAR_FILE ADD target/${JAR_FILE} /home/admin/app/
#
#
#
# 将启动命令写入启动脚本 start.sh
RUN echo "$JAVA_HOME/bin/java -jar $JAVA_OPTS -Ddubbo.address.ip=$POD_IP -Djava.security.egd=file:/dev/./urandom /home/admin/app/${JAR_FILE} --spring.profiles.active=prod" > /home/admin/start.sh && chmod +x /home/admin/start.sh
WORKDIR $CATALINA_HOME
ENTRYPOINT ["/bin/bash", "/home/admin/start.sh"]

打包镜像:

dockerfile-maven plugin自动镜像制作并发布

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.hush.k8s:provider >------------------------
[INFO] Building provider 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dockerfile-maven-plugin:1.4.4:build (default-cli) @ provider ---
[INFO] Building Docker context D:\2018\my_pro\demo\provider
[INFO]
[INFO] Image will be built as registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO]
[INFO] Step 1/9 : FROM registry.cn-hangzhou.aliyuncs.com/hush/basecontainer:20180929
[INFO]
[INFO] Pulling from hush/basecontainer
[INFO] Digest: sha256:35cdf59cd63e8f47cbb5ab595ad327f6ff2df8b910e34d958f83b942d072b713
[INFO] Status: Image is up to date for registry.cn-hangzhou.aliyuncs.com/hush/basecontainer:20180929
[INFO] ---> a8440ec1b0aa
[INFO] Step 2/9 : RUN mkdir -p /home/admin/app/
[INFO]
[INFO] ---> Using cache
[INFO] ---> c88518200882
[INFO] Step 3/9 : RUN mkdir -p /home/admin/tomcat/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 0f9dceff2421
[INFO] Step 4/9 : ENV CATALINA_HOME /home/admin/tomcat/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 0c8108c0b64e
[INFO] Step 5/9 : ARG JAR_FILE
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5df43a413985
[INFO] Step 6/9 : ADD target/${JAR_FILE} /home/admin/app/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5763c04c6c27
[INFO] Step 7/9 : RUN echo '$JAVA_HOME/bin/java -jar $JAVA_OPTS -Ddubbo.address.ip=$POD_IP -Djava.security.egd=file:/dev/./urandom "/home/admin/app/dubbo_provider.jar" --spring.profiles.active=prod' > /home/admin/start.sh && chmod +x /home/admin/start.sh
[INFO]
[INFO] ---> Using cache
[INFO] ---> 2789f23853b2
[INFO] Step 8/9 : WORKDIR $CATALINA_HOME
[INFO]
[INFO] ---> Using cache
[INFO] ---> b87c1ad13e7d
[INFO] Step 9/9 : ENTRYPOINT ["/bin/bash", "/home/admin/start.sh"]
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5debdfca2614
[INFO] Successfully built 5debdfca2614
[INFO] Successfully tagged registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO]
[INFO] Detected build of image with id 5debdfca2614
[INFO] Building jar: D:\2018\my_pro\demo\provider\target\dubbo_provider-docker-info.jar
[INFO] Successfully built registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.552 s
[INFO] Finished at: 2018-10-01T11:45:37+08:00
[INFO] ------------------------------------------------------------------------

在容器上可以执行docker images|grep <相应镜像名称>

docker push:

dockerfile-maven plugin自动镜像制作并发布

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.hush.k8s:provider >------------------------
[INFO] Building provider 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dockerfile-maven-plugin:1.4.4:build (default-cli) @ provider ---
[INFO] Building Docker context D:\2018\my_pro\demo\provider
[INFO]
[INFO] Image will be built as registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO]
[INFO] Step 1/9 : FROM registry.cn-hangzhou.aliyuncs.com/hush/basecontainer:20180929
[INFO]
[INFO] Pulling from hush/basecontainer
[INFO] Digest: sha256:35cdf59cd63e8f47cbb5ab595ad327f6ff2df8b910e34d958f83b942d072b713
[INFO] Status: Image is up to date for registry.cn-hangzhou.aliyuncs.com/hush/basecontainer:20180929
[INFO] ---> a8440ec1b0aa
[INFO] Step 2/9 : RUN mkdir -p /home/admin/app/
[INFO]
[INFO] ---> Using cache
[INFO] ---> c88518200882
[INFO] Step 3/9 : RUN mkdir -p /home/admin/tomcat/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 0f9dceff2421
[INFO] Step 4/9 : ENV CATALINA_HOME /home/admin/tomcat/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 0c8108c0b64e
[INFO] Step 5/9 : ARG JAR_FILE
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5df43a413985
[INFO] Step 6/9 : ADD target/${JAR_FILE} /home/admin/app/
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5763c04c6c27
[INFO] Step 7/9 : RUN echo '$JAVA_HOME/bin/java -jar $JAVA_OPTS -Ddubbo.address.ip=$POD_IP -Djava.security.egd=file:/dev/./urandom "/home/admin/app/dubbo_provider.jar" --spring.profiles.active=prod' > /home/admin/start.sh && chmod +x /home/admin/start.sh
[INFO]
[INFO] ---> Using cache
[INFO] ---> 2789f23853b2
[INFO] Step 8/9 : WORKDIR $CATALINA_HOME
[INFO]
[INFO] ---> Using cache
[INFO] ---> b87c1ad13e7d
[INFO] Step 9/9 : ENTRYPOINT ["/bin/bash", "/home/admin/start.sh"]
[INFO]
[INFO] ---> Using cache
[INFO] ---> 5debdfca2614
[INFO] Successfully built 5debdfca2614
[INFO] Successfully tagged registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO]
[INFO] Detected build of image with id 5debdfca2614
[INFO] Building jar: D:\2018\my_pro\demo\provider\target\dubbo_provider-docker-info.jar
[INFO] Successfully built registry.cn-hangzhou.aliyuncs.com/hush/dubbo_provider:1.0.4
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.552 s
[INFO] Finished at: 2018-10-01T11:45:37+08:00
[INFO] ------------------------------------------------------------------------

在镜像仓库可以直接查看

dockerfile-maven plugin自动镜像制作并发布

dockerfile-maven plugin自动镜像制作并发布

  dockerfile-maven plugin自动镜像制作并发布

  

上一篇:unity3D射线检测敌人是否在前方


下一篇:第18章 SysTick—系统定时器