Skip to content

Commit 4cfc4cb

Browse files
author
Ric Harvey
committed
allowing UID/GID mapping as per issue #73
1 parent 37f5667 commit 4cfc4cb

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,4 @@ VOLUME /var/www/html
232232

233233
EXPOSE 443 80
234234

235-
#CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
236235
CMD ["/start.sh"]

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ The following flags are a list of all the currently supported options that can b
6262
- **REAL_IP_HEADER** : set to 1 to enable real ip support in the logs
6363
- **REAL_IP_FROM** : set to your CIDR block for real ip in logs
6464
- **RUN_SCRIPTS** : Set to 1 to execute scripts
65+
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
66+
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)
6567

6668
### Dynamically Pulling code from git
6769
One of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time. Please take a look at our recommended [repo layout guidelines](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/repo_layout.md).
@@ -105,6 +107,18 @@ To pull a repository and specify a branch add the GIT_BRANCH environment variabl
105107
sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' -e 'GIT_BRANCH=stage' richarvey/nginx-php-fpm:latest
106108
```
107109

110+
### User / Group Identifiers
111+
112+
Sometimes when using data volumes (`-v` flags) permissions issues can arise between the host OS and the container. We avoid this issue by allowing you to specify the user `PUID` and optionally the group `PGID`. Ensure the data volume directory on the host is owned by the same user you specify and it will "just work" ™.
113+
114+
An example of mapping the UID and GID to the container is as follows:
115+
116+
```
117+
docker run -d -e "PUID=`id -u $USER`" -e "PGID=`id -g $USER`" -v local_dir:/var/www/html richarvey/nginx-php-fpm:latest
118+
```
119+
120+
This will pull your local UID/GID and map it into the container so you can edit on your host machine and the code will still run in the container.
121+
108122
### Custom Nginx Config files
109123
Sometimes you need a custom config file for nginx to achieve this read the [Nginx config guide](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/nginx_configs.md)
110124

scripts/start.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,17 @@ if [ ! -z "$PHP_UPLOAD_MAX_FILESIZE" ]; then
119119
sed -i "s/upload_max_filesize = 100M/upload_max_filesize= ${PHP_UPLOAD_MAX_FILESIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini
120120
fi
121121

122-
# Always chown webroot for better mounting
123-
chown -Rf nginx.nginx /var/www/html
122+
if [ ! -z "$PUID" ]; then
123+
if [ -z "$PGID" ]; then
124+
PGID=${PUID}
125+
fi
126+
deluser nginx
127+
addgroup -g ${PGID} nginx
128+
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx -u ${PUID} nginx
129+
else
130+
# Always chown webroot for better mounting
131+
chown -Rf nginx.nginx /var/www/html
132+
fi
124133

125134
# Run custom scripts
126135
if [[ "$RUN_SCRIPTS" == "1" ]] ; then

0 commit comments

Comments
 (0)