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 registries: (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

https://blog.csdn.net/boling_cavalry/article/details/78872020

猜你喜欢

转载自blog.csdn.net/qq_35119422/article/details/82025930