Skip to content

Mount a file in read/write mode for all in Docker

On my MacOS laptop I mounted a file in my newly created container using:

docker run --name mediawiki --link mysql:mysql -p 80:80 -v /Users/poiuytrez/Downloads/LocalSettings.php:/var/www/html/LocalSettings.php
 --rm poiuytrez/mediawiki:1.25.3

However, apache seems to have issues to read the file. We can learn by running a bash command in the container that the read permissions is not applied for all:

root@078252e20671:/var/www/html# ls -l LocalSettings.php
-rw-r----- 1 1000 staff 4857 Nov 18 15:44 LocalSettings.php

I tried the same process on docker installed on a Linux Debian 8 machine and I am getting:

root@16e34a9b169d:/var/www/html# ls -l LocalSettings.php
-rw-r--r-- 1 www-data www-data 4858 Nov 19 13:32 LocalSettings.php

which is much better for me.

How to add the read permissions for everybody without doing a chmod a+r on boot2docker/dockermachine?

I am using Docker 1.8.3



In docker-machine and boot2docker your /Users directory are mapped inside the virtual-machine at the same path, so when you map the volume like:

-v /Users/poiuytrez/Downloads/LocalSettings.php:/var/www/html/LocalSettings.php

actually is the boot2docker directory that you are mounting inside the container, so there is 2 levels.

You can see that the LocalSettings.php owner does not exist inside the container, so when you ls -l the user id are showing in your case userid 1000 and group staff.

-rw-r----- 1 1000 staff 4857 Nov 18 15:44 LocalSettings.php

1000 staff

Try to see the owner and the permissions inside boot2docker vm with boot2docker ssh or docker-machine ssh <you-machine-name> and ls -l inside it.

Other approach is to add an user with id 1000 inside your container and run your web server as this user.

You can also add a script to your container run command.

In Docker roadmap there are some improvements in user namespace to come in the next releases. I saw this article some days ago: I hope it solves this ownership issues.

User contributions licensed under: CC BY-SA
6 People found this is helpful