|
1 |
| -# eXistenZ' webstack container |
| 1 | +# Docker Builder |
2 | 2 |
|
3 |
| -A container running Nginx and PHP |
| 3 | +[](https://travis-ci.org/eXistenZNL/Docker-Webstack) [](https://hub.docker.com/r/existenz/webstack/) [](https://github.com/eXistenZNL/Docker-Webstack/blob/master/LICENSE) |
4 | 4 |
|
5 |
| -## Why |
| 5 | +## About |
| 6 | +This container is a fairly simple Nginx / PHP-FPM container that can be used as a base for your own web containers. It makes use of [s6-overlay](https://github.com/just-containers/s6-overlay) as it's init daemon / process supervisor, and comes in three flavours: PHP 5.6, PHP 7.0 and PHP 7.1. It is rebuilt and tested every day on Travis-CI, so you will always have the latest security patches of Nginx and PHP on hand. |
6 | 7 |
|
7 |
| -## What |
| 8 | +## Why? |
| 9 | +I can hear you thinking "aren't there already plenty good Nginx / PHP containers out there?". |
| 10 | +To me, there weren't, as I found that all existing containers either run some kind of bash script to start both Nginx and PHP, or use [supervisord](http://supervisord.org/) to start one or more processes in the background. |
| 11 | +The former felt really hacky to me, and the latter is not meant to be used as an init daemon as [it does not handle the different signals for process 1 properly](https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/) and makes your container possibly end up with zombie processes. |
8 | 12 |
|
9 |
| -## How to use this container |
| 13 | +So I started looking for proper init daemons that can take care of this situation and I found [s6-overlay](https://github.com/just-containers/s6-overlay) which explains in great detail how they overcame the aforementioned problems. |
10 | 14 |
|
11 |
| -### Advanced |
| 15 | +## The goals of this container |
| 16 | + |
| 17 | +- Be always up to date with the latest [packages from Alpine Linux](https://pkgs.alpinelinux.org/packages) |
| 18 | +- Minimize the lines of code needed in your own Dockerfile and optimize readibility. |
| 19 | +- Have sane defaults for Nginx, PHP, and FPM that can be easily overwritten if needed. |
| 20 | + |
| 21 | +## How can I use it? |
| 22 | + |
| 23 | +You can create your own containers based upon this container with a simple FROM in your Dockerfile. |
| 24 | + |
| 25 | +### Before you start |
| 26 | + |
| 27 | +Before start hacking away, you should know this: |
| 28 | +- Nginx runs under the system's nginx user, and PHP-FPM runs under the system's php user. |
| 29 | +- The code should be copied into /www, as this is the default directory Nginx and PHP work with in this container. |
| 30 | +- Any PHP modules needed in your project should be installed by using apk, Alpine Linux's package manager and the package names for installing can be looked up [here](https://pkgs.alpinelinux.org). |
| 31 | + |
| 32 | +Then there are some tips or rather guidelines that I adhere to personally, but ultimately this is just a matter of taste: |
| 33 | +- [S6-overlay can set permissions when the container starts up](https://github.com/just-containers/s6-overlay#fixing-ownership--permissions), but this can be slow if a lot of permissions need to be set, so just do this when building the container. |
| 34 | + |
| 35 | +### Basic example |
| 36 | +Now that we know all that, we can do something like this: |
| 37 | +``` |
| 38 | +FROM existenz/webstack:7.0 |
| 39 | +
|
| 40 | +COPY src/ /www |
| 41 | +
|
| 42 | +RUN chown -R php:nginx /www \ |
| 43 | + && find /www -type d -exec chmod -R 555 {} \; \ |
| 44 | + && find /www -type f -exec chmod -R 444 {} \; \ |
| 45 | + && find /www/var -type d -exec chmod -R 755 {} \; \ |
| 46 | + && find /www/var -type f -exec chmod -R 644 {} \; \ |
| 47 | + && apk -U --no-cache add \ |
| 48 | + php7-ctype \ |
| 49 | + php7-json \ |
| 50 | + php7-mbstring |
| 51 | +``` |
| 52 | +And you should now have a working container that runs your PHP project! |
| 53 | + |
| 54 | +### Overriding or extending the configuration |
| 55 | + |
| 56 | +If you want to augment of replace the configuration of Nginx, PHP or FPM, there are multiple options: |
| 57 | +- Place one or more configuration files in specific directories to augment the configuration |
| 58 | +- If that does not suit your needs, you can also simply overwrite the configuration files altogether |
| 59 | + |
| 60 | +These are the files to add or overwrite in order to configure the different parts of the webstack: |
| 61 | + |
| 62 | +| Application | Copy files into this directory | Overwrite this file if needed | |
| 63 | +|---------------------------|--------------------------------|-------------------------------| |
| 64 | +| PHP core directives (5.6) | /etc/php5/conf.d/ | /etc/php5/php.ini | |
| 65 | +| PHP-FPM (5.6) | /etc/php5/php-fpm.d/ | /etc/php5/php-fpm.conf | |
| 66 | +| PHP core directives (7.x) | /etc/php7/conf.d/ | /etc/php7/php.ini | |
| 67 | +| PHP-FPM (7.x) | /etc/php7/php-fpm.d/ | /etc/php7/php-fpm.conf | |
| 68 | +| Nginx | /etc/nginx/conf.d/ | /etc/nginx/nginx.conf | |
| 69 | + |
| 70 | +## Bugs, questions, and improvements |
| 71 | + |
| 72 | +If you found a bug or have a question, please open an issue on the GitHub Issue tracker. |
| 73 | +Improvements can be sent by a Pull Request against the master branch and are greatly appreciated! |
0 commit comments