注意必须安装docker及Maven

Maven的setting.xml中加入一下代码

 

  </servers>
    <server>
	   <id>docker-hub</id>
	   <username>用户名</username> 
	   <password>密码</password>
       <configuration>
	       <email>邮箱地址</email>
	   </configuration>	   
	</server>
  </servers>

 

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>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.docker04</groupId>
    <artifactId>springboot-docker-04</artifactId>
    <version>1.0</version>
    <name>springboot-docker-04</name>
    <packaging>jar</packaging>
    <description>springboot-docker-04</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <imageName>私有镜像ip:port/${artifactId}</imageName>
                    <imageTags>
                        <tag>${version}</tag> <!--指定镜像的版本标签-->
                    </imageTags>
                    <baseImage>java</baseImage>  <!--基于java构建-->
                    <entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <serverId>docker-hub</serverId>     <!--setting.xml中设置的id-->
                    <forceTags>true</forceTags>  <!--重复构建相同镜像则覆盖镜像-->
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

运行一下命令即可

mvn clean package docker:build

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐