Change uid of www-data user before starting apache#286
Change uid of www-data user before starting apache#286Vampouille wants to merge 3 commits intodocker-library:masterfrom
Conversation
|
I don't known if there is a way to split long entrypoint line with json format. |
|
@Vampouille I think we should create separate sh file for entrypoint. |
|
@ihor-sviziev I just updated my PR with a dedicated shell script. I also check if UID need to be changed. |
|
I think apache2-foreground should be moved to CMD in Dockerfile. In general it looks very good for me! |
|
I move |
|
Can I run |
|
@tianon Do you think this PR have a chance to be merged ? |
|
I'm not comfortable with the PHP image doing With #282 (and #291), changing the runtime user should be possible with $ docker run -dit --name apache-nobody -e APACHE_RUN_USER=nobody php:7.0-apache
763df5c2d7012678a270d7ef021919323c12e87b4471ed52755164b7e833440e
$ docker logs apache-nobody
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Fri Sep 02 16:45:34.496215 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/7.0.10 configured -- resuming normal operations
[Fri Sep 02 16:45:34.496233 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
$ docker top apache-nobody
UID PID PPID C STIME TTY TIME CMD
root 29375 29361 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND
nobody 29406 29375 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND
nobody 29407 29375 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND
nobody 29408 29375 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND
nobody 29409 29375 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND
nobody 29410 29375 0 09:45 pts/9 00:00:00 apache2 -DFOREGROUND |
|
Thanks for your answer, the purpose of this PR is to be able to run apache with numeric uid 999. It seems that 999 as uid is common across docker images. You can look at postgres official images : In docker env, when you share some named volumes, textual username is not used. Docker does not make translation or mapping between user of containers. So files owners are only identify by numeric value. If I try to launch apache with uid 999, it complains about not finding user with uid 999 :
In my PR, |
|
https://github.com/docker-library/php/pull/286/files#diff-8874cb4a06e835f8683c251ffad0fb3fR11 I think that |
| WANTED_UID=${RUN_AS_UID:-33} | ||
|
|
||
| # check if UID need to be updated | ||
| if [ $CURRENT_UID -ne $WANTED_UID ]; then |
There was a problem hiding this comment.
I tried using this same code in a different docker image to change the www-data UID and needed to tweak this line to if [ "$CURRENT_UID" -ne "$WANTED_UID" ]; then, and the above to WANTED_UID=${RUN_AS_UID}
There was a problem hiding this comment.
CURRENT_UID and WANTED_UID should not be empty because :
idcommand always return numeric identifier${RUN_AS_UID:-33}use 33 as default value ifRUN_AS_UIDis not set
Can you explain steps to reproduce your issue, maybe your www-data default uid was not set to 33.
There was a problem hiding this comment.
@Vampouille that makes sense.. I'm not clear why the ID was not set by default on my instance, but based on what you're saying it doesn't seem like this change needs to be made. Thanks for taking the time to respond!
|
Beyond the solution of
This is adaptable to use users other than $ docker run -it --rm -u 999 87926a4f33dc
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.16. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.16. Set the 'ServerName' directive globally to suppress this message
[Wed Apr 05 21:09:22.110035 2017] [core:error] [pid 1] (13)Permission denied: AH00099: could not create /var/run/apache2/apache2.pid
[Wed Apr 05 21:09:22.110068 2017] [core:error] [pid 1] AH00100: apache2: could not log pid to file /var/run/apache2/apache2.pidThanks for the contribution and discussion! ❤️ |
This PR is a proposal to fix #14 with use of
usermodcommand.This PR replace entrypoint with 3 commands :
usermodon www-data to change uid with value of RUN_AS_UID env variablechownon directory previously owned by www-dataapache2-foreground