使用 gitlab CI 构建 docker 图像并推送到自签名的 https nexus repo

Build docker images with gitlab CI and push to self signed https nexus repo

我有一个 gitlab CI 设置,我想在其中构建和推送 docker 图像,第一个问题是我的 nexus 存储库不是 https。 实际的错误信息是这样的:

Error response from daemon: Get http://some.host:port/v2/: http: server gave HTTP response to HTTPS client

要构建 docker 图像,我们使用 docker:latest 图像,我找不到在 .gitlab-ci.yml

中将我们的主机添加为不安全注册表的方法

所以一个自签名的我的 nexus 存储库希望它能解决,但它也不起作用并给出以下错误消息:

Error response from daemon: Get https://some.host:port/v2/: x509: certificate signed by unknown authority

这是我当前的 CI 设置:

image: docker:latest

services:
  - docker:dind

before_script:
  - docker info
  - docker login -u USER -p PASSWORD some.host:port

stages:
  - build

build-image:
  stage: build
  script:
    - docker build -t some.host:port/image:alpine .
    - docker push some.host:port/image:alpine
  only:
    - master
  when: manual

那么有没有一个简单的解决方案或现有的 docker 图像,我可以在其中配置不安全的注册表可能是一些 docker 命令行的魔法我真的需要创建一个自己的图像来解决这个问题吗?

您可以使用不同的命令启动 docker dind。详情见下文url

https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#setting-a-command-for-the-service。所以你需要更新你的 .gitlab.ci.yml

image: docker:latest

services:
- name: docker:dind
  command: [ "--insecure-registry=some.host:port" ]

before_script:
  - docker info
  - docker login -u USER -p PASSWORD some.host:port

stages:
  - build

build-image:
  stage: build
  script:
    - docker build -t some.host:port/image:alpine .
    - docker push some.host:port/image:alpine
  only:
    - master
  when: manual

然后你可以使用不安全的 http 注册表

在语法上稍作修改后为我工作,命令需要数组。

services:
- name: docker:dind
  command: ["--insecure-registry=some.host:port"]