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:
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?
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! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With