Q:

Fix umask for future RUN commands in dockerfile

I would like to fix a certain umask for all my RUN commands in the remainder of a dockerfile. Instead of writing this
RUN umask 0002 && do_something

I would like to do something like this
RUN echo umask 0002 >> some_file
RUN do_something
...

I have tried setting the umask for root in various ways but none of them seem to take effect on the following RUN commands. Any ideas?

A:

Docker doesn't initialise each RUN step as a full login shell might, it's creates a pretty minimal environment. 
The umask is set to 0022 by runc when a container is started which is also not configurable. 
So, like most Docker builds, you may need to chain the commands into one RUN step so it's all under the same shell process. 
RUN set -uex; \
    umask 0002; \
    do_something; \
    do_otherthing;

Otherwise you will need to do some type of initialisation in every RUN step. 

