DinD图像缓存中间图像

DinD图像缓存中间图像

本文介绍了如何让gitlab-ci-runner DinD图像缓存中间图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Docker文件,从安装texlive-full包开始,这个包是巨大的,需要很长时间。如果我在本地使用 docker build ,则安装后创建的中间映像被缓存,后续版本快速。

I have a Dockerfile that starts with installing the texlive-full package, which is huge and takes a long time. If I docker build it locally, the intermedate image created after installation is cached, and subsequent builds are fast.

但是,如果我推送到我自己的GitLab安装并且GitLab-CI构建运行程序启动,这总是似乎从头开始,重新加载 FROM 映像,并且做apt-重新安装这似乎对我来说是一个巨大的浪费,所以我试图找出如何让GitLab DinD的图像缓存中间的图像之间的建立,没有运气到目前为止。

However, if I push to my own GitLab install and the GitLab-CI build runner starts, this always seems to start from scratch, redownloading the FROM image, and doing the apt-get install again. This seems like a huge waste to me, so I'm trying to figure out how to get the GitLab DinD image to cache the intermediate images between builds, without luck so far.

我试过使用 - cache-dir - docker-cache-dir gitlab-runner注册命令,无济于事。

I have tried using the --cache-dir and --docker-cache-dir for the gitlab-runner register command, to no avail.

这甚至是gitlab-runner DinD图像应该是可以做吗?

Is this even something the gitlab-runner DinD image is supposed to be able to do?

我的 .gitlab-ci.yml

build_job:
    script:
    - docker build --tag=example/foo .

我的 Dockerfile

FROM php:5.6-fpm
MAINTAINER Roel Harbers <[email protected]>
RUN apt-get update && apt-get install -qq -y --fix-missing --no-install-recommends texlive-full
RUN echo Do other stuff that has to be done every build.

我使用GitLab CE 8.4.0和gitlab / gitlab-runner:最新as runner, / p>

I use GitLab CE 8.4.0 and gitlab/gitlab-runner:latest as runner, started as

docker run -d --name gitlab-runner --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /usr/local/gitlab-ci-runner/config:/etc/gitlab-runner \
    gitlab/gitlab-runner:latest \
; \

运动员使用以下方式注册:

The runner is registered using:

docker exec -it gitlab-runner gitlab-runner register \
    --name foo.example.com \
    --url https://gitlab.example.com/ci \
    --cache-dir /cache/build/ \
    --executor docker \
    --docker-image gitlab/dind:latest \
    --docker-privileged \
    --docker-disable-cache false \
    --docker-cache-dir /cache/docker/ \
; \

这将创建以下 config.toml

concurrent = 1
[[runners]]
    name = "foo.example.com"
    url = "https://gitlab.example.com/ci"
    token = "foobarsldkflkdsjfkldsj"
    tls-ca-file = ""
    executor = "docker"
    cache_dir = "/cache/build/"
    [runners.docker]
        image = "gitlab/dind:latest"
        privileged = true
        disable_cache = false
        volumes = ["/cache"]
        cache_dir = "/cache/docker/"

(我已经尝试了 cache_dir docker_cache_dir disable_cache ,都具有相同的结果:没有缓存)

(I have experimented with different values for cache_dir, docker_cache_dir and disable_cache, all with the same result: no caching whatsoever)

推荐答案

我想没有简单的答案你的问题。在添加一些细节之前,我强烈建议您阅读,最初名为不要在Docker for CI中使用Docker。

I suppose there's no simple answer to your question. Before adding some details, I strongly suggest to read this blog article from the maintainer of DinD, which was originally named "do not use Docker in Docker for CI".

您可能尝试的是声明 / var / lib / docker 作为您的GitLab转轮的卷。但请注意,根据您的文件系统驱动程序,您可能会在主机上的AUFS文件系统上的容器中使用AUFS,这很可能会导致问题。

What you might try is declaring /var/lib/docker as a volume for your GitLab runner. But be warned, depending on your file-system drivers you may use AUFS in the container on an AUFS filesystem on your host, which is very likely to cause problems.

什么我建议您正在创建一个独立的 Docker-VM,仅适用于跑步者,并且将/ code> docker.sock 从VM进入你的转轮容器。
我们正在使用GitLab这个设置取得巨大成功(大约在12个月内建立了大约27.000)。

What I'd suggest to you is creating a separate Docker-VM, only for the runner(s), and bind-mount docker.sock from the VM into your runner-container.We are using this setup with GitLab with great success (>27.000 builds in about 12 months).

你可以看看我们的,这实际上是基于shell执行器GitLab的跑步者。

You can take a look at our runner with docker-compose support which is actually based on the shell-executor of GitLab's runner.

这篇关于如何让gitlab-ci-runner DinD图像缓存中间图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:41