springboot~maven进行docker打包与推送

maven进行docker打包与推送

  • docker.host 表示本地的docker主机,tcp走2375端口
  • docker.registry 表示私服地址,本例使用harbor做为私服
<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>${docker.plugin.version}</version>
    <configuration>
        <!-- Docker本地主机 -->
        <dockerHost>${docker.host}</dockerHost>
        <!-- Docker 镜像私服-->
        <registry>${docker.registry}</registry>
        <!-- 认证信息-->
        <authConfig>
            <push>
                <username>${docker.username}</username>
                <password>${docker.password}</password>
            </push>
        </authConfig>
        <images>
            <image>
                <name>${docker.registry}/${docker.namespace}/${project.name}:${project.version}</name>
                <build>
                    <dockerFile>${project.basedir}/Dockerfile</dockerFile>
                </build>
            </image>
        </images>
    </configuration>
</plugin>
  • 本地docker主机需要开启2375这个tcp端口
# 打开配置文件
vi /usr/lib/systemd/system/docker.service
# 添加2375端口
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# 重新加载配置文件并重启服务
systemctl daemon-reload
systemctl restart docker
  • 通过plugins的docker插件,进行build和push即可,需要注意本地docker主机与私服之间需要进行daemon.json的配置
{
  "registry-mirrors": ["https://ay50ucm9.mirror.aliyuncs.com","http://f2d6cb40.m.daocloud.io"],
  "insecure-registries":["http://192.168.xx.xxx:8888"]
}
  • maven推送
mvn clean package docker:stop docker:remove docker:build docker:run
# 或者直接打包推送:mvn docker:build docker:push
  • 输出
[INFO] --- docker-maven-plugin:0.40.1:push (default-cli) @ lind-fast-demo ---
[INFO] DOCKER> The push refers to repository [192.168.60.137:8888/lind-fast/lind-fast-demo]
edf103f27075: Preparing   
9f6bd6be39e5: Preparing   
d3f8c53ca74a: Preparing   
f9a0984f718a: Preparing   
2104e5b926f6: Preparing   
50644c29ef5a: Preparing   
50644c29ef5a: Waiting     
edf103f27075: Pushing     [>                                                  ]     512B/26.28kB
9f6bd6be39e5: Pushing      2.048kB
edf103f27075: Pushing     [==================================================>]  28.67kB
2104e5b926f6: Mounted from moxm/java 
d3f8c53ca74a: Mounted from moxm/java 
f9a0984f718a: Mounted from moxm/java 
edf103f27075: Pushed      
9f6bd6be39e5: Pushed      
50644c29ef5a: Mounted from moxm/java 
[INFO] DOCKER> 1.0.0: digest: sha256:47e560ca99e91aa73770a86991f68167510724d8a1da2820d8d3e24f64c85ddd size: 1575
[INFO] DOCKER> Temporary image tag skipped. Target image '192.168.60.137:8888/lind-fast/lind-fast-demo:1.0.0' already has registry set or no registry is available
[INFO] DOCKER> Pushed 192.168.60.137:8888/lind-fast/lind-fast-demo:1.0.0 in 3 seconds 
  • 其它问题
    如果你的docker:build失败,提示你的基础镜像不存在,我们可以把基础镜像添加到harbor中,模拟成为harbor中的镜像就可以了
posted @ 2022-07-28 11:13  张占岭  阅读(715)  评论(0编辑  收藏  举报