Host directory owner changes #73

Closed
opened 2016-09-13 20:52:27 +00:00 by nclavaud · 10 comments
nclavaud commented 2016-09-13 20:52:27 +00:00 (Migrated from github.com)

When mapping a host directory to the container volume /var/www/html, the owner of the host directory changes. This is annoying, because any update to the code will require changing the owner back.

$ ls -n
drwxrwxr-x 2 1000 1000 4096 sept. 13 22:04 src

$ docker run -d -v $PWD/src:/var/www/html richarvey/nginx-php-fpm
3d7321f9fba01f7ff36970b7525b840e24f36af0ff66d07e21a1814e64b84d09

$ ls -n
drwxrwxr-x 2  100  101 4096 sept. 13 22:04 src

I guess this is because of github.com/ngineered/nginx-php-fpm@8137d2d0c5/scripts/start.sh (L92-L93)

Is it expected behavior, or am I missing something?

When mapping a host directory to the container volume `/var/www/html`, the owner of the host directory changes. This is annoying, because any update to the code will require changing the owner back. ``` $ ls -n drwxrwxr-x 2 1000 1000 4096 sept. 13 22:04 src $ docker run -d -v $PWD/src:/var/www/html richarvey/nginx-php-fpm 3d7321f9fba01f7ff36970b7525b840e24f36af0ff66d07e21a1814e64b84d09 $ ls -n drwxrwxr-x 2 100 101 4096 sept. 13 22:04 src ``` I guess this is because of https://github.com/ngineered/nginx-php-fpm/blob/8137d2d0c5e1b9afa36ba2781a027184dc46ad4b/scripts/start.sh#L92-L93 Is it expected behavior, or am I missing something?
richarvey commented 2016-09-14 08:24:30 +00:00 (Migrated from github.com)

Yeah its expected behaviour as it allows the web server to write to the directory, if you're uploading files or plugins like wordpress etc.

I could add a flag to stop change of ownership if you think it would be useful.

Ric

Yeah its expected behaviour as it allows the web server to write to the directory, if you're uploading files or plugins like wordpress etc. I could add a flag to stop change of ownership if you think it would be useful. Ric
virtuman commented 2016-11-28 20:59:56 +00:00 (Migrated from github.com)

wouldn't it be better to use best-practices with GID and UID mapping?
ie: create user and group with specified IDs, if IDs are defined in environment vars.

sample implementation:
https://github.com/sameersbn/docker-gitlab#host-uid--gid-mapping
https://github.com/sameersbn/docker-gitlab/search?utf8=%E2%9C%93&q=USERMAP_GID

wouldn't it be better to use best-practices with GID and UID mapping? ie: create user and group with specified IDs, if IDs are defined in environment vars. sample implementation: https://github.com/sameersbn/docker-gitlab#host-uid--gid-mapping https://github.com/sameersbn/docker-gitlab/search?utf8=%E2%9C%93&q=USERMAP_GID
virtuman commented 2016-11-29 04:00:38 +00:00 (Migrated from github.com)

in the case of your image, the easiest would be something like:
ENV USERMAP_UID=101
ENV USERMAP_GID=100

addgroup -gid USERMAP_GID nginx &&
useradd -g USERMAP_UID -u USERMAP_UID nginx && \

But the more complete example is here, nice way of handling it, although, handling it from Dockerfile seems more than sufficient:
https://github.com/27Bslash6/docker/blob/master/nginx-pagespeed/bin/add_user.sh

in the case of your image, the easiest would be something like: ENV USERMAP_UID=101 ENV USERMAP_GID=100 addgroup -gid USERMAP_GID nginx && \ useradd -g USERMAP_UID -u USERMAP_UID nginx && \ But the more complete example is here, nice way of handling it, although, handling it from Dockerfile seems more than sufficient: https://github.com/27Bslash6/docker/blob/master/nginx-pagespeed/bin/add_user.sh
virtuman commented 2016-11-29 04:02:05 +00:00 (Migrated from github.com)

And it's still beneficial to have an ability to bypass ownership change, ie. wordpress would have only few folders writable by php-fpm user, and the rest should be read only

And it's still beneficial to have an ability to bypass ownership change, ie. wordpress would have only few folders writable by php-fpm user, and the rest should be read only
aamche commented 2016-12-02 05:15:10 +00:00 (Migrated from github.com)

Docker also has the --user flag when creating containers. Is it possible to map to that? then no need to add extra variables, and could use docker functionality.

Docker also has the --user flag when creating containers. Is it possible to map to that? then no need to add extra variables, and could use docker functionality.
hsklia commented 2017-01-31 09:52:28 +00:00 (Migrated from github.com)

Please fix this issue

Please fix this issue
richarvey commented 2017-02-10 10:33:19 +00:00 (Migrated from github.com)

Has anyone got a working pull request for this. We'll need to change the running user of nginx and php-fpm also.

Ric

Has anyone got a working pull request for this. We'll need to change the running user of nginx and php-fpm also. Ric
royrico commented 2017-02-11 22:18:44 +00:00 (Migrated from github.com)

running into this issue too.

Here's a possible solution:
create a completely new user based upon user&group ids passed into the container
have NGINX run as that user

based upon example here:
https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/10-adduser#L19

so from your docker.sh file you'd have

docker run -d -p 80:80 -e PGID=1000 PUID=1000 ...

if you think this solution is appropriate, I can take a stab at implementing this, then can submit a PR

running into this issue too. Here's a possible solution: create a completely new user based upon user&group ids passed into the container have NGINX run as that user based upon example here: https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/10-adduser#L19 so from your docker.sh file you'd have `docker run -d -p 80:80 -e PGID=1000 PUID=1000 ...` if you think this solution is appropriate, I can take a stab at implementing this, then can submit a PR
richarvey commented 2017-02-12 23:07:11 +00:00 (Migrated from github.com)

I'm going to check this out in the morning and get it merged

I'm going to check this out in the morning and get it merged
richarvey commented 2017-02-13 10:21:23 +00:00 (Migrated from github.com)

commit 4cfc4cb998 fixes this enjoy!

commit 4cfc4cb998f4b981ff5b5b97d37111dc7a874dd4 fixes this enjoy!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ric/nginx-php-fpm#73
No description provided.