如果在持续集成中使用Docker,如何使Docker不占用磁盘空间 [英] How can I make docker to not eat up disk space if used in Continuous integration

查看:90
本文介绍了如果在持续集成中使用Docker,如何使Docker不占用磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与docker一起玩,并计划在GitLab CI环境中使用它,以将当前项目状态打包到容器中,并提供运行中的实例进行审查。



I使用一个非常简单的Dockerfile如下:

  FROM php:7.0-apache 
RUN sed -i's!/ var / www / html!/ var / www / html / public!g'/etc/apache2/sites-available/000-default.conf
COPY。 / var / www / html /

现在,只要有一个新的(空)文件( 触摸foobar )到当前目录并调用

  docker build -t test2 -rm。 

再次,将创建一个包含所有代码的全新图层。



如果我不创建新文件,则旧图像似乎可以很好地重用。



我有一个半途而废的解决方案以下 Dockerfile

  FROM test2:latest 
RUN sed -i's!/ var / www / html!/ var / www / html / public!g'

/etc/apache2/sites-available/000-default.conf
COPY。 / var / www / html /



深入研究该问题并将存储驱动程序切换为 overlay ,这似乎正是我想要的-仅添加了几个字节新的层。没有。



是否有更好的解决方案?

解决方案

一个建议是使用命令 docker image prune 清理悬空的图像。这样可以节省很多空间。您可以在CI中定期运行此命令。


I am playing with docker and plan to use it in a GitLab CI environment to package the current project state to containers and provide running instances to do reviews.

I use a very simple Dockerfile as follows:

FROM php:7.0-apache
RUN  sed -i 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/000-default.conf
COPY . /var/www/html/

Now, as soon as a I a new (empty) file (touch foobar) to the current directory and call

docker build -t test2 --rm .

again, a full new layer is created, containing all of the code.

If I do not create a new file, the old image seems to be nicely reused.

I have a half-way solution using the following Dockerfile:

FROM test2:latest
RUN  sed -i 's!/var/www/html!/var/www/html/public!g' 

/etc/apache2/sites-available/000-default.conf COPY . /var/www/html/

After digging into that issue and switching the storage driver to overlay, this seems to be what I want - only a few bytes are added as a new layer.

But now I am wondering, how I could integrate this into my CI setup - basically I would need two different Dockerfiles - depending on whether the image already exists or it doesn't.

Is there a better solution for this?

解决方案

One suggestion is to use the command docker image prune to clean dangling images. This can save you a lot of space. You can run this command regularly in your CI.

这篇关于如果在持续集成中使用Docker,如何使Docker不占用磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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