【备忘录】docker-maven-plugin 使用

在使用docker-maven-plugin 插件时,经常会碰到一些奇怪的问题:

比如:

1、docker远程访问时,认证安全问题?

2、dockerHost 访问地址准确性?

3、需要多个tag时如何处理?

4、push 到仓库时,需要保留历史记录问题?

反正各种问题,没有找到任何相关资源能完整的说明,踩坑之后备忘,重点内容直接详细注释说明:

shell 复制代码
<!--使用docker-maven-plugin插件-->
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.2.2</version>
    <configuration>
        <imageName>${project.artifactId}:${project.version}</imageName>
        <!-- 指定 Dockerfile 路径-->
        <dockerDirectory>${basedir}</dockerDirectory>
        <!-- 这里的tag会在build环境中打上,支持多个tag-->
        <imageTags>
            <imageTag>latest</imageTag>
        </imageTags>
        <!-- 根据认证的情况,确保是否时http或https,默认2375对应http,2376对应https-->
        <dockerHost>https://x.x.x.x:2376</dockerHost>
        <!--如果docker 已经做的安装认证,这里需要放认证客户端访问需要的几个文件:默认:ca.key,cert.pem,key.pem-->
        <!--注意几个文件的名称必须为如上几个默认的名称,比如把上面几个文件放在:/home/xxxx/cert-->
        <dockerCertPath>/home/xxxx/cert</dockerCertPath>
    <executions>
        <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
        <execution>
            <id>tag-image</id>
            <phase>package</phase>
            <goals>
                <goal>tag</goal>
            </goals>
            <configuration>
                <image>${project.artifactId}:${project.version}</image>
                <newName>${docker.repostory}/${docker.registry.namespace}/${project.artifactId}:latest</newName>
            </configuration>
        </execution>
        <execution>
            <id>push-image</id>
            <phase>verify</phase>
            <goals>
                <goal>push</goal>
            </goals>
            <configuration>
                <!--如果有设置maven settting,这里是setting中的server id,如果自己的私服,也可以是任意值,请根据实际配置-->
                <serverId>${docker.serverId}</serverId>
                <imageName>${docker.repostory}/${docker.registry.namespace}/${project.artifactId}:latest</imageName>
                <!--这里就可以在push 多个tag到仓库,注意前提是已经存在该tag的image-->
                <imageTags>
                    <imageTag>${project.version}</imageTag>
                    <imageTag>latest</imageTag>
                </imageTags>
            </configuration>
        </execution>
    </executions>
</plugin>
相关推荐
Sheffield7 小时前
Alpine是什么,为什么是Docker首选?
linux·docker·容器
马艳泽7 小时前
win10下运行Start Broker and Proxy报错解决
docker
用户13573999256601 天前
Windows 从 0 搭建 WSL2 原生 AI 开发环境:Codex + Docker + VSCode
docker
vi_h1 天前
在 macOS 上通过 Docker 安装并运行 Ollama(详细可执行教程)
macos·docker·ollama
黑心老魔1 天前
通过 Docker 创建开发环境
docker·开发环境
冬奇Lab2 天前
一天一个开源项目(第41篇):Workout.cool - 现代化开源健身教练平台,训练计划与进度追踪
docker·开源·资讯
天朝八阿哥2 天前
使用Docker+vscode搭建离线的go开发调试环境
后端·docker·visual studio code
阿虎儿3 天前
Docker安装(非sudo用户可用)
docker
fetasty4 天前
rustfs加picgo图床搭建
docker
蝎子莱莱爱打怪5 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes