使用 GitLab CI 构建并推送 docker 图像

build and push docker images with GitLab CI

我想使用 GitLab CI

构建 docker 图像并将其推送到我的本地 nexus 存储库

这是我当前的 CI 文件:

image: docker:latest

services:
  - docker:dind

before_script:
  - docker info
  - docker login -u some_user -p nexus-rfit some_host

stages:
  - build

build-deploy-ubuntu-image:
  stage: build
  script:
    - docker build -t some_host/dev-image:ubuntu ./ubuntu/
    - docker push some_host/dev-image:ubuntu
  only:
    - master
  when: manual

我也有一个 alpin docker 的工作,但是当我想 运行 任何一个时,它都失败了,并出现以下错误:

Checking out 13102ac4 as master... Skipping Git submodules setup $ docker info Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ERROR: Job failed: exit code 1

从技术上讲,图像中的 docker 守护程序不是 运行ning,但我不知道为什么?

GitLab 人员在他们的文档中提供了关于在基于 docker 的作业中使用 docker-build 的参考:https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#use-docker-in-docker-executor。由于您似乎已准备就绪(即工作的正确图像和额外的 docker:dind 服务),这很可能是 运行ner-config 问题。

如果您查看文档中的第二步:

  1. Register GitLab Runner from the command line to use docker and privileged mode:

    [...]

    Notice that it's using the privileged mode to start the build and service containers. If you want to use docker-in-docker mode, you always have to use privileged = true in your Docker containers.

可能您使用的 运行ner 未在特权模式下配置 因此无法正确 运行 docker 里面的守护进程。您可以直接在注册的 运行 用户上编辑 /etc/gitlab-runner/config.toml 以添加该选项。

(此外,请阅读文档部分,了解与您 choose/your 运行 用户在使用 dind 时支持的存储驱动程序相关的性能的更多信息)