使用GitLab CI构建和推送Docker镜像

5
我希望能够使用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

我还有一个关于alpine 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守护程序没有运行,但我不知道为什么。

1个回答

7
GitLab的文档中提到了在基于Docker的作业中使用docker-build的参考资料:https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#use-docker-in-docker-executor。由于您似乎已经准备好了一切(即适合该作业的正确镜像和附加的docker:dind服务),所以很可能是运行器配置问题。
如果您查看文档中的第二个步骤:
  1. 从命令行注册GitLab Runner以使用docker和特权模式:

    [...]

    请注意,它使用特权模式启动构建和服务容器。如果要使用docker-in-docker模式,则始终必须在Docker容器中使用privileged = true

很可能您正在使用未配置为特权模式的运行器,因此无法正确运行内部的docker守护进程。您可以直接编辑已注册的运行器上的/etc/gitlab-runner/config.toml以添加该选项。
(此外,请阅读文档中有关存储驱动程序选择/运行器支持使用dind时性能的更多信息的部分)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接