链接:docker安装本地仓库
使用maven 打包jar成docker镜像 并发布到镜像库
1 maven settings.xml配置server 节点添加
(这是私有库 用户名密码)1
2
3
4
5<server>
<id>docker-hub</id>
<username>testuser</username>
<password>testpassword</password>
</server>
2 项目 pom.xml
properties 节点
1 | <docker.image.prefix>reg.itmuch.com</docker.image.prefix> |
maven 配置组件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <!-- docker的maven插件,官网:https://github.com/spotify/docker-maven-plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<!-- 镜像名:tag -->
<imageName>${docker.image.prefix}/${project.artifactId}:${tag.version}</imageName>
<!-- 指定Dockerfile所在的路径 -->
<dockerDirectory>${project.basedir}/docker</dockerDirectory>
<!-- 以下两行是为了docker push到DockerHub使用的。 -->
<serverId>${docker.servcerId}</serverId>
<registryUrl>${docker.registry}</registryUrl>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
参考https://github.com/spotify/docker-maven-plugin
3 dockerFile文件放在项目根目录下docker目录
1 | FROM openjre |
4 maven build docker and push Image:
mvn clean package docker:build -DpushImage
(需要注意:运行环境必须有docker)