一、IDEA发布镜像至Docker
1.1IDEA安装Docker插件
1.2配置Docker服务器地址
1.3编写POM.XML文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>3.1.6</version>-->
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.csdn</groupId>
<artifactId>blog</artifactId>
<name>blog</name>
<description>Demo project for Spring Boot</description>
<properties>
<dadao.version>1.0.0-RELEASE</dadao.version>
<java.version>1.8</java.version>
<docker.host>192.168.10.194:2375</docker.host>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>blog-${dadao.version}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-base:latest</builder>
</image>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<!--如果package时不想用docker打包,就注释掉这个goal-->
<!--<goal>build</goal>-->
<!--<goal>push</goal>-->
</goals>
</execution>
</executions>
<configuration>
<!-- 远程docker地址 -->
<dockerHost>${docker.host}</dockerHost>
<!--镜像名-->
<imageName>${project.artifactId}</imageName>
<!--TAG,这里用工程版本号-->
<imageTags>
<imageTag>${project.version}</imageTag>
</imageTags>
<!--指定Dockerfile路径-->
<dockerDirectory>${project.basedir}</dockerDirectory>
<!--suppress UnresolvedMavenProperty -->
<entryPoint>["java","-Xmx512m", "-Xms256m", "-jar","/${project.build.finalName}.jar","--spring.profiles.active=${profiles.active}"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
1.4编写Docker配置文件
1.5编写服务
Name:自定义
Dockerfile:选择上一步创建的Dockerfile文件
ImageTag:镜像标签自定义
ContainerName:容器名称自定义
BindPort:前一个是服务器对外暴露端口(访问服务使用),后一个是容器端口。
1.6上传镜像至Docker
maven package:进行打包
run:进行推送
1.7Docker镜像上传至Harbor镜像服务器
登录私有仓库
docker login -u admin -p harbor密码 192.168.10.194:9526
将镜像进行标记
# docker tag 镜像名称:镜像版本 harbor服务器IP:harbor服务器端口/harbor中创建的项目/上传到harbor中镜像名称:上传到harbor中镜像版本
docker tag blog:latest 192.168.10.194:9526/public/blog:latest
上传镜像
docker push 192.168.10.194:9526/public/blog:latest
二、IDEA发布镜像至Harbor服务器
2.1修改Pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>3.1.6</version>-->
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.csdn</groupId>
<artifactId>blog</artifactId>
<name>blog</name>
<description>Demo project for Spring Boot</description>
<properties>
<dadao.version>1.0.0-RELEASE</dadao.version>
<java.version>1.8</java.version>
<harbor.namespace>public</harbor.namespace>
<docker.host>192.168.10.194:2375</docker.host>
<harbor.host>192.168.10.194:9526</harbor.host>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>blog-${dadao.version}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-base:latest</builder>
</image>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<!--如果package时不想用docker打包,就注释掉这个goal-->
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<!--是否跳过推送镜像是Harbor false:不跳过,进行推送 true:跳过,不推送镜像至Harbor-->
<skip>false</skip>
<!-- 上下文路径配置,此处设置为项目根路径 用来读取Dockerfile-->
<contextDirectory>${project.basedir}</contextDirectory>
<!--允许使用settings.xml中配置访问远程构件库的认证信息 -->
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<!--上传路径/镜像构建名: 私服地址/私服项目名/springboot项目名-->
<repository>${harbor.host}/${harbor.namespace}/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.2修改Pom文件
信息: I/O exception (java.io.FileNotFoundException) caught when processing request to {}->npipe://localhost:80: \\.\pipe\docker_engine (系统找不到指定的文件。)