I can\'t understand why the \'chown\' command should increase the size of my docker image?
The following Dockerfile creates an image of size 5.3MB:
Since Docker 17.09 one can use --chown flag on ADD/COPY operations in Dockerfile to change the owner in the ADD/COPY step itself rather than a separate RUN operation with chown which increases the size of the image as you have noted. It would have been good to have this as the default mode i.e. the permissions of the user copying the files are applied to the copied files. However, the Docker team did not want to break backward compatibility and hence introduced a new flag.
COPY --chown=:
The other alternatives are: 1. Change the permission in a staging folder prior to building the image.
Run the container via a bootstrap script that changes the ownership.
Squash the layers!