Docker-in-Docker与Gitlab共享跑步者,用于构建并将Docker图像推送到注册表 [英] Docker-in-Docker with Gitlab Shared runner for building and pushing docker images to registry

查看:142
本文介绍了Docker-in-Docker与Gitlab共享跑步者,用于构建并将Docker图像推送到注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图设置Gitlab CI,可以建立码头图像,并发现DinD最初只能针​​对单独的跑步者和博客文章建议即将为共享跑步者启用

Been trying to set-up Gitlab CI which can build a docker image, and came across that DinD was enabled initially only for separate runners and Blog Post suggest it would be enabled soon for shared runners,

运行DinD需要启用跑步者中的特权模式,在注册跑步者时被设置为标志,但找不到共享跑步者的等效机制

Running DinD requires enabling privileged mode in runners, which is set as a flag while registering runner, but couldn't find an equivalent mechanism for Shared Runners

推荐答案

共享跑步者现在能够构建Docker图像。这是您可以使用的工作:

The shared runners are now capable of building Docker images. Here is the job that you can use:

stages:
  - build
  - test
  - deploy

# ...
# other jobs here
# ...

docker:image:
  stage: deploy
  image: docker:1.11
  services:
    - docker:dind
  script:
    - docker version
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    # push only for tags
    - "[[ -z $CI_BUILD_TAG ]] && exit 0"
    - docker tag $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_BUILD_TAG
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:$CI_BUILD_TAG

此作业假定您正在使用Gitlab提供的容器注册表。只有当构建提交被标记为版本号时,它才会推送图像。

This job assumes that you are using the Container Registry provided by Gitlab. It pushes the images only when the build commit is tagged with a version number.

注意您将需要缓存或生成作为您的服务的任何依赖关系的临时工件,这些工作未在存储库中提交。这应该是在其他工作中完成的。例如 node_modules 通常不包含在存储库中,必须从 build / test stage。

Note that you will need to cache or generate as temporary artifacts of any dependencies for your service which are not committed in the repository. This is supposed to be done in other jobs. e.g. node_modules are not generally contained in the repository and must be cached from the build/test stage.

这篇关于Docker-in-Docker与Gitlab共享跑步者,用于构建并将Docker图像推送到注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆