多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
1、maven配置: maven对docker的支持插件有两种版本 **最新版本:dockerfile-maven-plugin** ``` <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${docker.plugin.version}</version> </plugin> ``` **老版本:docker-maven-plugin** ``` <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker.plugin.version}</version> </plugin> ``` 我们使用新版本。 我们在maven中定义参数: > docker.registry.url 参数是我们要发布镜像的 image id 前缀 > docker.registry.host 参数是我们要发布镜像的私服地址 ![](https://img.kancloud.cn/bc/f5/bcf5cc8d42dcc789e4cfaffbca8aff1e_706x52.png) 2、在maven pom文件 build --> plugins 节点,对要发布的应用进行如下配置 ``` <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${docker.plugin.version}</version> <executions> <execution> <id>tag-latest</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>latest</tag> </configuration> </execution> <execution> <id>tag-version</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>${project.version}</tag> </configuration> </execution> </executions> <configuration> <contextDirectory>${project.basedir}</contextDirectory> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> <repository>${docker.registry.url}/blade/${project.artifactId}</repository> <tag>${project.version}</tag> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> ``` 3、在maven的setting.xml文件中增加私服镜像发布账号信息(如果私服不允许匿名发布的话) 在 标签servers下增加: ``` <server> <id>register.docker.beree.net</id> <username>账户名</username> <password>密码</password> <configuration> <email>邮箱</email> </configuration> </server> ``` 到此项目中maven的配置就结束了,接下来我们配置 Dockerfile 文件。