zoukankan      html  css  js  c++  java
  • springboot项目打包docker镜像maven插件

    <!-- profile docker config -->
        <profiles>
            <profile>
                <id>docker</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.spotify</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <version>0.4.14</version>
                            <executions>
                                <!-- when executing mvn package, it will execute mvn docker:build at the same time -->
                                <execution>
                                    <id>build-image</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>build</goal>
                                    </goals>
                                </execution>
                                <!-- when executing mvn package, it will execute mvn docker:build -DpushImage at the same time -->
                                <execution>
                                    <id>push-image</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>push</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <imageName>${env.DOCKER_REGISTRY_NAME}/${docker.image.prefix}/${project.artifactId}</imageName>
                                <imageTags>
                                    <imageTag>${project.version}</imageTag>
                                    <imageTag>latest</imageTag>
                                </imageTags>
                                <forceTags>true</forceTags>
                                <dockerDirectory>${project.artifactId}/src/main/docker</dockerDirectory>
                                <serverId>docker-registry</serverId>
                                <registryUrl>${env.DOCKER_REGISTRY}</registryUrl>
                                <dockerCertPath>${env.DOCKER_CERT_PATH}</dockerCertPath>
                                <resources>
                                    <resource>
                                        <targetPath>/</targetPath>
                                        <directory>${project.build.directory}</directory>
                                        <include>${project.build.finalName}.jar</include>
                                    </resource>
                                </resources>
                                <buildArgs>
                                    <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                                </buildArgs>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
    
                <activation>
                    <property>
                        <name>env</name>
                        <value>docker</value>
                    </property>
                </activation>
            </profile>
        </profiles>
    

    其中

    env.DOCKER_REGISTRY_NAME = hub.xx.com:10443
    env.DOCKER_REGISTRY= https://hub.xx.com:10443
    env.DOCKER_CERT_PATH = E:Doccerthub.xx.com
    env.DOCKER_HOST =  tcp://172.168.1.1:2375
    

    注意:
    最终的镜像一定要是~/~/~:~ 格式,如

    ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
    

    mvn的setting配置

    开放docker的2375端口方法

    vim /usr/lib/systemd/system/docker.service
    ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
    
    #重新加载docker配置
    systemctl daemon-reload // 1,加载docker守护线程
    systemctl restart docker // 2,重启docker
    

    如果需要有docker服务器推送到私有中央仓库且为https协议,需要在/etc/docker/certs.d目录下配置证书,证书放置文件夹为私有仓库的域名如hub.123.com:10443

  • 相关阅读:
    Neutron 理解 (1): Neutron 所实现的虚拟化网络 [How Netruon Virtualizes Network]
    openstack里面的Provider network 和 Tenant network 的区别
    Openstack网络相关概念比较复杂,经常使人混淆,本文进行相关说明。
    OpenStack 网络:Neutron 初探
    openstack 网络架构 nova-network + neutron
    Java 性能测试的四项原则
    微信公众号开发之微信买单
    微信公众号开发之如何使用JSSDK
    微信公众号开发之如何一键导出微信所有用户信息到Excel
    [内核驱动] 链表LIST_ENTRY的操作(转)
  • 原文地址:https://www.cnblogs.com/zhangww/p/13049343.html
Copyright © 2011-2022 走看看