gpt4 book ai didi

docker - 使用Jib和Gitlab-CI构建docker镜像

转载 作者:行者123 更新时间:2023-12-02 21:10:58 25 4
gpt4 key购买 nike

我正在尝试创建一个管道,在该管道中使用JIB(通过Maven插件)创建docker镜像并将其推送到我的Gitlab注册表。

当我登录到Docker注册表时,这在本地可以正常工作。

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<allowInsecureRegistries>true</allowInsecureRegistries>
<from>
<image>dockerhost/projectgroup/alpine</image>
</from>
<to>
<image>dockerhost/project/imagename:${project.version}</image>
</to>
<container>
<useCurrentTimestamp>true</useCurrentTimestamp>
</container>
</configuration>
</plugin>

说我有一个.gitlab-ci.yml,看起来像:
stages:
- build_image

build_image:
stage: build_image
tags:
- dev
script: |
mvn compile jib:build

现在,在触发管道时出现异常
Build image failed: Failed to authenticate with registry dockerhost/projectgroup/alpine because: peer not authenticated

我假设我收到此错误是因为我没有运行docker login -u [用户名] -p [密码/ token ]

我怎么需要一个使用docker-in-docker镜像的.gitlab-ci.yml来在我的脚本中运行docker登录?

除了使用docker-in-docker镜像在Gitlab CI上构建该镜像之外,还有其他选择吗?

最佳答案

使用GitLab,您可以定义 secret 环境变量,可用于将注册表凭据传递给Jib。

  • Define secret variables using gitlab
  • 使用Jib传递注册表凭据
    mvn compile jib:build -Djib.to.image=my-container-image:latest -Djib.to.auth.username=$REGISTRY_USER -Djib.to.auth.password=$REGISTRY_PASSWORD
  • 关于docker - 使用Jib和Gitlab-CI构建docker镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54683567/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com