将图层存储在gitlab ci docker executor中 [英] Store layers in gitlab ci docker executor

查看:85
本文介绍了将图层存储在gitlab ci docker executor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中正在使用gitlab CI,并且我创建了用于进行测试和构建的映像.当我在docker executor中运行它时,每个工作都需要从开始下载图像.有什么方法可以在主机上缓存/存储该层吗?喜欢缓存吗?我试过存储/var/lib/docker/aufs,但不是让所有人想到的.在任何地方都找不到任何解决方案.有人遇到过这个问题吗?如何使用它?

I'm working on gitlab CI at my project, and I created image to make my tests and builds. When I ran it in docker executor every job needs to download images from beggining. Is there any way to cachee/store that layers at host? like cache? I tried store /var/lib/docker/aufs but I guest its not everythink. Can't find any solution anywhere. Anyone has that problem before? How to work with it?

gitlab-ci.yml

phpunit: stage: test script: - docker run -w /var/www -v $(pwd):/var/custom --rm phpunit/phpunit:4.8.5

phpunit: stage: test script: - docker run -w /var/www -v $(pwd):/var/custom --rm phpunit/phpunit:4.8.5

gitlab-ci.yml,其中的卷来自

phpunit: stage: test script: - docker run -w /var/www -v $(pwd):/var/custom --rm --volumes-from {image_from other build} phpunit/phpunit:4.8.5

phpunit: stage: test script: - docker run -w /var/www -v $(pwd):/var/custom --rm --volumes-from {image_from other build} phpunit/phpunit:4.8.5

推荐答案

最有效的选择是使用长时间运行的专用docker:dind容器:

The option that works best would be to use a dedicated long-running docker:dind container like this:

docker run --privileged --name gitlab-dind -d --restart=always  docker:dind

(如果主机支持,请添加--storage-driver = overlay2!)

(add --storage-driver=overlay2 if your host supports it!)

然后按如下所示修改config.toml:

Then modify config.toml as follows:

[runners.docker]
  tls_verify = false
  image = "docker:latest"   <--------
  privileged = false     <--------
  disable_cache = false
  volumes = ["/cache"]
  links = ["gitlab-dind:docker"]   <-----------
  shm_size = 0
[runners.cache]

然后删除

services:
- docker:dind

来自.gitlab-ci.yml

from .gitlab-ci.yml

如果您要从.gitlab-ci.yml运行docker容器,则可以这样做:

If you want to run a docker container from .gitlab-ci.yml, you can do it like this:

test:
  stage: test
  image: phpunit/phpunit:4.8.5
  script:
  - cd your_source && phpunit

请注意,由于我不了解phpunit,因此我猜测的是最后一行.

Note I am guessing about the last line, since I don't know phpunit.

这篇关于将图层存储在gitlab ci docker executor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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