Reputation: 13
I am fairly new to Docker and have been setting up a Dockerfile and compose file to start up a server for testing.
When running a centos:6.6 image with a volume mapped to my user directory in OSX and installing httpd, my user for var/www/html is 1000:ftp instead of root:root.
I need to change a folder to user apache:apache in order to be able to upload files to it and cannot get chown or chmod to make any changes in any folder under var/www/html.
I know this has to do with me mapping my volume to a location on my OS drive.
So, my question is..
Is there anyway to set it up so that I can change ownership of var/www/html?
Upvotes: 1
Views: 1037
Reputation: 3024
The newly released Docker for Mac has a different behavior regarding ownership:
Initially, any containerized process that requests ownership metadata of an object is told that its uid and gid own the object. When any containerized process changes the ownership of a shared file system object, e.g. with chown, the new ownership information is persisted in the com.docker.owner extended attribute of the object. [...]
Michael's start_safe_perms
script can be adapted like the following to work consistently across platforms:
if [[ -n $(mount -t fuse.osxfs) ]]; then
chown -R www-data:www-data . 2> /dev/null
# ...
else
read owner group owner_id group_id < <(stat -c '%U %G %u %g' .)
adduser --system --uid=$(stat -c %u .) "$owner"
# ...
fi
It basically detects if the mounted volume if of the type fuse.osxfs
.
You can checkout API Platform's start_safe_perms
script for a fully working example: https://github.com/api-platform/api-platform/blob/master/docker/apache/start_safe_perms
Upvotes: 2
Reputation: 1326676
Issues 587 or 581 show that you can not change the ownership of a host mounted directory.
Change instead your Apache start script in order to start it with the right id (1000) instead of apache:apache.
See "apache/start_safe_perms" from Michael A. Smith
Mainly:
read owner group owner_id group_id < <(stat -c '%U %G %u %g' .)
adduser --system --uid=$(stat -c %u .) "$owner"
Upvotes: 1