KubeSphere应用【五】发布镜像至Harbor

2023-12-21 20:52:31

一、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镜像服务器

。。。

二、IDEA发布镜像至Harbor服务器

。。。

文章来源:https://blog.csdn.net/u013292160/article/details/135138390
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。