springboot集成docker

maven添加依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- Docker maven plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.12</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>

使用aliyun镜像私库

  1. maven配置私库账号密码
    配置setting.xml文件 ${user.home}/.m2/settings.xml, 这里的${user.home}就是用户主目录,windows里在C:\Users\下你的用户名目录,mac在/Home/下你的用户名目录
1
2
3
4
5
6
7
8
9
10
...
<server>
<id>registry.cn-beijing.aliyuncs.com</id>
<username>topcatii@126.com</username>
<password>********</password>
<configuration>
<email>topcatii@126.com</email>
</configuration>
</server>
...

这里的密码用明文是比较危险的,所以还要加密

  1. 创建master password
1
mvn --encrypt-master-password <password>

这个命令会生成一条类似{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}的字符串
将这个生成的字符串存储在${user.home}/.m2/settings-security.xml文件里

1
2
3
<settingsSecurity>
<master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>
  1. 生成服务器密码
1
mvn --encrypt-password <password>

得到类似{COQLCE6DU6GtcS5P=}的字符串,替换到上面的setting.xml文件中

1
2
3
4
5
6
7
8
9
10
...
<server>
<id>registry.cn-beijing.aliyuncs.com</id>
<username>topcatii@126.com</username>
<password>{COQLCE6DU6GtcS5P=}</password>
<configuration>
<email>topcatii@126.com</email>
</configuration>
</server>
...

使用maven命令打包发布

1
mvn package dockerfile:build dockerfile:push

参考:

0%