Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify umask in Dockerfile

Tags:

php

docker

apache

I'm using Mac OS and recently I'm trying to set up a development environment with docker. Docker seems to be nice, but currently I'm facing the following problem:

PROBLEM:

Whenever PHP (in the docker container) is creating a folder with a subfolder, apache results in a 500-error. Apache-log: "... Can't create directory app/../../folder/subfolder/subsubfolder/"

I assume that this is caused by the environment variable umask, because whenever a folder is created, it doesn't have write permission. Because of that subfolders can't be created and so on.

To test this out, I wrote a little test-script (umask-test.php):

$umask = umask(0);
echo ("umask = $umask <br>");

And bingo! Every time I build and run the container and start the script via the browser, the result is:

umask = 18

GOAL:

So I would like to have umask always to be set to 000 (zero)

I figured out, the best place to set this variable would be the Dockerfile, so in the Dockerfile I stated the following:

FROM ubuntu:trusty
...
ENV UMASK 0
...

Problem is, that this results in nothing:

  • the test-script gives out 18 for umask
  • folders are still created with the wrong permission
  • subfolders can't be created.

QUESTIONS:

What am I doing wrong?

How can umask in docker containers always be set to zero?

How can I permit the apache-user (www-data) to create folders that always have write-permissions and in which subfolders can be created?

like image 887
codiga Avatar asked Jun 11 '16 08:06

codiga


1 Answers

Problem solved

Since hopefully this is helpful for other, I want to provide the answer to my own question:

The problem is not docker and umask-settings in the container. The problem is the Mac and the umask-setting on the Mac OS!!

Example: If umask on the Mac is set to 022, then folders created on mounted directories by docker have the permissions 755. This causes, that no subfolders can be created.

This link is providing the information about how to set umask for the Mac: https://support.apple.com/en-us/HT201684

So if you type in your terminal

 sudo launchctl config user umask 000

and reboot, all your folders will be created with 777-permissions. Including the folders mounted to docker.

Before I was asking myself why running containers (initialized with run -v ...) are not really working. Now it seems to work all right! :-)

like image 144
codiga Avatar answered Sep 28 '22 07:09

codiga