docker-maven-plugin 打包镜像,命令解释_08
- 1、不带推送命令:
- <plugin>
- <groupId>com.spotify</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <version>0.4.13</version>
- <!-- executions 将插件绑定在指定的phase执行-->
- <executions>
- <execution>
- <id>build-image</id>
- <phase>package</phase>
- <!--只需将插件的goal绑定在某个phase,添加后,执行mvn package 时,插件自动为我们构建Docker 镜像 -->
- <goals>
- <goal>build</goal>
- </goals>
- </execution>
- <execution>
- </executions>
- <configuration>
- //指定镜像名称
- <imageName>springboot</imageName>
- //指定标签名称
- <imageTags>
- <imageTag>1.0.1</imageTag>
- </imageTags>
- // 为true,则表示推送镜像
- <pushImage>true</pushImage>-->
- // Dockerfile 地址
- <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
- // Docker 地址
- <dockerHost>http://111...99:2375</dockerHost>
- style="line-height: 24px;"><resources>
- <resource>
- <targetPath>/</targetPath>
- <directory>${project.build.directory}</directory>
- <include>${project.build.finalName}.jar</include>
- </resource>
- <resource>
- </resources>
- <!--如需重复构建相同标签名称的镜像,可将forceTags设为true,这样就会覆盖构建相同标签的镜像。-->
- <forceTags>true</forceTags>
- <imageName>springboot</imageName>
- </configuration>
- <executions>
- </plugin>
- <plugin>
- 2、带推送
- <plugin>
- <groupId>com.spotify</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <version>0.4.13</version>
- <!-- executions 将插件绑定在指定的phase执行-->
- <executions>
- <execution>
- <id>build-image</id>
- <phase>package</phase>
- <!--只需将插件的goal绑定在某个phase,添加后,执行mvn package 时,插件自动为我们构建Docker 镜像 -->
- <goals>
- <goal>build</goal>
- </goals>
- <goals>
- </execution>
- </executions>
- <configuration>
- <imageName>springboot</imageName>
- <!--可推送镜像到私有仓库,只需要将imageName指定成类似于如下的形式即可:0.0.4 为标签名称,也可以通过imagTag设置 -->
- <imageName>localhost:5000/{仓库名称}/discovery:0.0.4</imageName>
- <imageTags>
- <imageTag>1.0.1</imageTag>
- </imageTags>
- // Dockerfile 地址
- <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
- // Docker 地址
- <dockerHost>http://111...99:2375</dockerHost>
- <resources>
- <resource>
- <targetPath>/</targetPath>
- <directory>${project.build.directory}</directory>
- <include>${project.build.finalName}.jar</include>
- </resource>
- <resource>
- </resources>
- <!-- 与maven配置文件settings.xml中配置的server.id一致,用于推送镜像 -->
- <serverId>springboot</serverId>
- <registryUrl>${docker.repostory}</registryUrl>
- <pushImage>true</pushImage>-->
- <imageName>springboot</imageName>
- </configuration>
- </plugin>
- <plugin>
- 如果要推送,要修改 Maven的全局配置文件setttings.xml,在其中添加以下内容
- <server>
- <id>docker-aliyun</id>
- <username>你的DockerHub用户名</username>
- <password>你的DockerHub密码</password>
- <configuration>
- <email>你的DockerHub邮箱</email>
- </configuration>
- </server>
- <server>