Why does `chmod` cause `docker build` to run out of disk space Why does `chmod` cause `docker build` to run out of disk space docker docker

Why does `chmod` cause `docker build` to run out of disk space


It's not chmod that is causing the extra disk space. The run command in Dockerfile creates a layer caching that will use up your disk space. I would suggest to aggregate the commands you run using &&.


Filesystem layers in docker are implemented with a copy-on-write solution. Any change to a file results in a copy of that file first, and then the change is applied to that file copy, even a permission, owner, or timestamp. The chown and chmod commands, when run recursively, will change timestamps on the file, even if no permissions are changed.

Therefore to minimize the size of layers in docker, make all changes to a file in the same layer. Each step creates a new layer, so consolidate changes into the same step. With a COPY command, fix the permissions on the source and see the options to adjust ownership. And with RUN, you will often see commands chained with the && syntax to compact into a single step. This is particularly important when creating temporary files, since you need to delete them before the step finishes to avoid writing them into the image layer.