maven构建docker镜像push到镜像仓库方式

 更新时间:2023年11月28日 09:09:19   作者:乄名007  
这篇文章主要介绍了maven构建docker镜像push到镜像仓库方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

maven构建docker镜像push到镜像仓库

registry私人镜像仓库

docker pull hub.c.163.com/library/registry:latest
 
Docker tag imageid registry
 
docker run -d -p 5000:5000 -v /Users/zhongxing/docker/registry/opt:/var/lib/registry registry

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
 
	<artifactId>base-eureka</artifactId>
	<packaging>jar</packaging>
 
	<name>base-eureka</name>
	<description>Demo project for Spring Boot</description>
 
	<parent>
		<groupId>com.zxing</groupId>
		<artifactId>base-ms</artifactId>
		<version>1.0-SNAPSHOT</version>
	</parent>
 
	<properties>
		<docker.registry>192.168.20.200:5000</docker.registry>
		<push.image>true</push.image>
	</properties>
 
	<dependencies>
 
		<dependency>
			<groupId>net.logstash.logback</groupId>
			<artifactId>logstash-logback-encoder</artifactId>
			<version>4.10</version>
		</dependency>
 
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		</dependency>
 
	</dependencies>
 
	<build>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
			</resource>
			<resource>
				<directory>${env}</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>com.spotify</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.4.13</version>
				<configuration>
					<imageName>${docker.registry}/${project.groupId}/${project.artifactId}:${project.version}</imageName>
					<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
					<pushImage>${push.image}</pushImage>
					<resources>
						<resource>
							<directory>${project.build.directory}</directory>
							<include>${project.build.finalName}.jar</include>
						</resource>
					</resources>
				</configuration>
			</plugin>
		</plugins>
	</build>
 
 
</project>

Dockerfile:

FROM java:8
ADD base-eureka-1.0-SNAPSHOT.jar app.jar
CMD ["java","-jar","app.jar"]

mac配置insecure registrie 

(docker push fail。。。)

maven运行:

docker:build

打包结果:

运行:

docker run -d -p 8761:8761 --name=eureka 192.168.20.200:5000/com.zxing/base-eureka:1.0-SNAPSHOT

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

最新评论