Search code examples
dockerdockerfileumask

Why is umask setting in dockerfile not working?


I want some directory in my docker to have a specific umask value, say 000. I tried to set that in my dockerfile and in the ENTRYPOINT shell script, but they both failed to work,

...
RUN umask 000 /var/www/html/storage/logs //the directory
ENTRYPOINT  ["/etc/start.sh"]

#in the /etc/start.sh
#!/bin/sh
umask 000 /var/www/html/storage/logs
...

When I log into docker container and check /var/www/html/storage/logs umask, it is still the default 0022

/var/www/html # cd storage/logs/
/var/www/html/storage/logs # umask
0022

Why is that? How do I make it work ? Thanks!


Solution

  • The umask is a property of a process, not a directory. Like other process-related characteristics, it will get reset at the end of each RUN command.

    If you're trying to make a directory writeable by a non-root user, the best option is to chown it to that user. (How to set umask for a specific folder on Ask Ubuntu has some further alternatives.) None of this will matter if the directory is eventually a bind mount or volume mount point; all of the characteristics of the mounted directory will replace anything that happens in the Dockerfile.

    If you did need to change the umask the only place you can really do it is in an entrypoint wrapper script. The main container process can also set it itself.

    #!/bin/sh
    # entrypoint.sh
    umask 000
    # ... other first-time setup ...
    exec "$@"