Skip to content

Commit ccf6727

Browse files
committed
Reup over stderr handling issues with php-fpm
- Removes /manifest (pain to manage) - Updates README - Updates examples, removes composer example - Replaces logging setup for php / nginx - Dirty hack to exit supervisord on exit of either nginx or php-fpm. (replace with event listener?) - Sets error logging defaults - Removes ini files, use passthrough from php-fpm pool conf, sets some admin ones to prevent children causing issues
1 parent 3bed549 commit ccf6727

17 files changed

+157
-176
lines changed

Dockerfile

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
FROM alpine:3.7
22

3-
# Setup user & /var/www dir
4-
RUN adduser -D -u 1000 -g 1000 -s /bin/sh -h /var/www www-data
3+
# Create user
4+
RUN adduser -D -u 1000 -g 1000 -s /bin/sh www-data && \
5+
mkdir -p /www && \
6+
chown -R www-data:www-data /www
57

6-
# PHP/FPM + Modules
8+
# Install tini - 'cause zombies - see: https://github.com/ochinchina/supervisord/issues/60
9+
# (also pkill hack)
10+
RUN apk add --no-cache --update tini
11+
12+
# Install a golang port of supervisord
13+
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/bin/supervisord
14+
15+
# Install nginx & gettext (envsubst)
16+
# Create cachedir and fix permissions
17+
RUN apk add --no-cache --update \
18+
gettext \
19+
nginx && \
20+
mkdir -p /var/cache/nginx && \
21+
chown -R www-data:www-data /var/cache/nginx && \
22+
chown -R www-data:www-data /var/lib/nginx && \
23+
chown -R www-data:www-data /var/tmp/nginx
24+
25+
# Install PHP/FPM + Modules
726
RUN apk add --no-cache --update \
827
php7 \
928
php7-apcu \
@@ -36,36 +55,20 @@ RUN apk add --no-cache --update \
3655
php7-zlib \
3756
php7-zmq
3857

39-
# tini - 'cause zombies - see: https://github.com/ochinchina/supervisord/issues/60
40-
# gettext - nginx envsubst
41-
RUN apk add --no-cache --update \
42-
tini \
43-
gettext \
44-
nginx && \
45-
rm -rf /var/www/localhost
46-
47-
# Fix nginx dirs/perms
48-
RUN mkdir -p /var/cache/nginx && \
49-
chown -R www-data:www-data /var/cache/nginx && \
50-
chown -R www-data:www-data /var/lib/nginx && \
51-
chown -R www-data:www-data /var/tmp/nginx
52-
53-
# Install a golang port of supervisord
54-
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/bin/supervisord
55-
5658
# Runtime env vars are envstub'd into config during entrypoint
5759
ENV SERVER_NAME="localhost"
5860
ENV SERVER_ALIAS=""
59-
ENV SERVER_ROOT=/var/www
61+
ENV SERVER_ROOT=/www
62+
6063
# Alias defaults to empty, example usage:
6164
# SERVER_ALIAS='www.example.com'
6265

63-
COPY manifest /
64-
65-
WORKDIR /var/www
66-
67-
# nginx: 80, xdebug: 9000 (currently disabled)
68-
EXPOSE 80 9000
66+
COPY ./supervisord.conf /supervisord.conf
67+
COPY ./php-fpm-www.conf /etc/php7/php-fpm.d/www.conf
68+
COPY ./nginx.conf.template /nginx.conf.template
69+
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
6970

70-
ENTRYPOINT ["tini", "--"]
71-
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
71+
# Nginx on :80
72+
EXPOSE 80
73+
WORKDIR /www
74+
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]

README.md

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ This image runs supervisord in the foreground which in turn runs nginx/php-fpm i
2020

2121
### Example standalone usage (available at http://localhost/)
2222

23-
`docker run --rm -it -p80:80 lslio/nginx-php-fpm`
23+
`docker run --rm -it -p80:80 -v ~/www:/www lslio/nginx-php-fpm`
2424

2525
### Example usage with volume map and server name change (available at http://example.localhost/)
2626

27-
`docker run --rm -it -v ~/my/src:/var/www -p 80:80 -e SERVER_NAME=example.localhost lslio/nginx-php-fpm`
27+
`docker run --rm -it -v ~/www:/www -p 80:80 -e SERVER_NAME=example.localhost lslio/nginx-php-fpm`
2828

2929
### Example [Dockerfile](https://github.com/lsl/docker-nginx-php-fpm/blob/master/examples/Dockerfile.basic) usage
3030

@@ -33,45 +33,21 @@ FROM lslio/nginx-php-fpm
3333
3434
ENV SERVER_NAME=example.com
3535
ENV SERVER_ALIAS=www.example.com
36-
ENV SERVER_ROOT=/var/www
36+
ENV SERVER_ROOT=/www
3737
38-
COPY . /var/www
39-
```
40-
41-
### Example [Dockerfile](https://github.com/lsl/docker-nginx-php-fpm/blob/master/examples/Dockerfile.composer) usage with a [composer](https://github.com/lsl/docker-composer) build step
42-
43-
(Use [lslio/composer](https://github.com/lsl/docker-composer) for faster builds.)
44-
45-
```
46-
FROM lslio/composer:latest as composer
47-
48-
COPY ./composer.* /var/www/
49-
RUN composer-install -d /var/www
50-
51-
COPY . /var/www
52-
RUN composer-dump-autoload -d /var/www
53-
54-
FROM lslio/nginx-php-fpm
55-
56-
# Install extra modules (if you need them)
57-
# RUN apk add --no-cache --update -X 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' php7-msgpack php7-gearman
58-
59-
ENV SERVER_NAME=example.com
60-
ENV SERVER_ALIAS=www.example.com
61-
ENV SERVER_ROOT=/var/www
62-
63-
COPY --from=composer --chown=www-data:www-data /var/www /var/www
38+
COPY . /www
6439
```
6540

6641
### Example [docker-compose.yml](https://github.com/lsl/docker-nginx-php-fpm/blob/master/examples/docker-compose.yml)
42+
6743
```
6844
version: '3.6'
6945
7046
services:
7147
example:
7248
image: lslio/nginx-php-fpm
7349
volumes:
74-
- .:/var/www
50+
- .:/www
7551
ports:
7652
- "80:80"
7753
environment:
@@ -93,20 +69,20 @@ services:
9369
example-web:
9470
image: lslio/nginx-php-fpm
9571
volumes:
96-
- ./web:/var/www
72+
- ./web:/www
9773
environment:
9874
VIRTUAL_HOST: "example.localhost"
99-
SERVER_ROOT: "/var/www/public"
75+
SERVER_ROOT: "/www/public"
10076
10177
example-api:
10278
image: lslio/nginx-php-fpm
10379
volumes:
104-
- ./api:/var/www
80+
- ./api:/www
10581
environment:
10682
VIRTUAL_HOST: "api.example.localhost"
107-
SERVER_ROOT: "/var/www/public"
83+
SERVER_ROOT: "/www/public"
10884
```
10985

11086
## Props
11187
- Got a lot of ideas from [boxedcode/alpine-nginx-php-fpm](https://gitlab.com/boxedcode/alpine-nginx-php-fpm).
112-
- This golang [supervisord port](https://github.com/ochinchina/supervisord) reduces the final image by about half.
88+
- This golang [supervisord port](https://github.com/ochinchina/supervisord) reduces the final image by about half.
File renamed without changes.

docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh -e
2+
3+
# jwilder/nginx-proxy support
4+
SERVER_NAME=${VIRTUAL_HOST:-${SERVER_NAME:-localhost}}
5+
6+
envsubst '$SERVER_NAME $SERVER_ALIAS $SERVER_ROOT' < /nginx.conf.template > /etc/nginx/nginx.conf
7+
8+
supervisord -c /supervisord.conf
9+

examples/Dockerfile.basic renamed to examples/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM lslio/nginx-php-fpm
22

33
ENV SERVER_NAME=example.com
44
ENV SERVER_ALIAS=www.example.com
5-
ENV SERVER_ROOT=/var/www
5+
ENV SERVER_ROOT=/www
66

7-
COPY . /var/www
7+
COPY . /www

examples/Dockerfile.composer

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/docker-compose-multisite.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Example running multiple laravel applications
2+
# behind nginx-proxy for development
13
version: '3.6'
24

35
services:
@@ -11,15 +13,15 @@ services:
1113
example-web:
1214
image: lslio/nginx-php-fpm
1315
volumes:
14-
- ./web:/var/www
16+
- ./web:/www
1517
environment:
1618
VIRTUAL_HOST: "example.localhost"
17-
SERVER_ROOT: "/var/www/public"
19+
SERVER_ROOT: "/www/public"
1820

1921
example-api:
2022
image: lslio/nginx-php-fpm
2123
volumes:
22-
- ./api:/var/www
24+
- ./api:/www
2325
environment:
2426
VIRTUAL_HOST: "api.example.localhost"
25-
SERVER_ROOT: "/var/www/public"
27+
SERVER_ROOT: "/www/public"

examples/docker-compose.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
version: '3.6'
22

33
services:
4-
example:
4+
builder:
55
image: lslio/nginx-php-fpm
6+
build: ../
7+
entrypoint: /bin/true
8+
9+
example:
10+
image: lslio/nginx-php-fpm-example
11+
build: ./
612
volumes:
7-
- .:/var/www
13+
- .:/www
814
ports:
915
- "80:80"
1016
environment:
11-
SERVER_NAME: "example.localhost"
17+
SERVER_NAME: "example.localhost"
18+

examples/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
phpinfo();

manifest/etc/php7/conf.d/xx_xdebug.ini

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)