How can I make docker to not eat up disk space if used in Continuous integration

让人想犯罪 __ 提交于 2019-12-11 07:37:46

问题


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?


回答1:


Build your images with same tags or no tags

docker build -t myapp:ci-build ....

or

docker build ....

If you use same tags then old images will be untagged and will have "" as name. If you don't tag them then also they will have "" in name.

Now you can schedule below command

docker system prune -f

This will remove all dangling images containers etc




回答2:


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.



来源:https://stackoverflow.com/questions/45907363/how-can-i-make-docker-to-not-eat-up-disk-space-if-used-in-continuous-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!