You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2align="center">🐳 A preconfigured, extendable, multistage, PHP Symfony 4.3+ Docker Image for Production and Development</h2>
5
-
<palign="center">.</p>
4
+
<h2align="center">🐳 Production Grade, Rootless, Pre-configured, Extendable, and Multistage
5
+
6
+
PHP Docker Image for Cloud Native Deployments (and Kubernetes)</h2>
7
+
8
+
<h4align="center">compatible with popular PHP Frameworks such as <ahref="https://laravel.com/">Laravel 5+</a> & <ahref="https://symfony.com/">Symfony 4+</a> and their variants.</h4>
@@ -41,27 +42,48 @@ The Image utilizes multistage builds to create multiple targets optimized for **
41
42
- Designed to run in orchestrated environments like Kubernetes.
42
43
- Multi-Container setup with `Nginx` & `PHP-FPM` communicating via TCP.
43
44
- Production Image that are **immutable** and **fully contained** with source code and dependencies inside.
45
+
- Configured for graceful shutdowns/restarts, and correctly pass termination signal.
44
46
- Multi-stage builds for an optimized cache layers.
45
47
- Transparent configuration, all configuration determine app behavior are captured in VCS, such as PHP, FPM, and Nginx Config
46
48
- Production configuration with saint defaults tuned for performance.
47
-
- Easily extend the image with extra configuration, and scripts; with predictable execution.
48
-
- Fast container start time.
49
-
-Development Image supports mounting code and hot-reloading.
49
+
- Easily extend the image with extra configuration, and scripts; such as post-build & pre-run scripts.
50
+
- Fast container start time done by only doing the necessary steps at application start and offload anything else to build.
51
+
-Override-able container CMD, used to run PHP Commands, to be used for cron-jobs/consumers.
50
52
- Image tries to fail at build time as much as possible by running all sort of checks.
53
+
- Default Healtchecks embedded for PHP FPM and Nginx
54
+
- Development Image supports mounting code and hot-reloading.
51
55
52
56
## How to add to my project ?
53
57
54
58
- Copy this repository`Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` to your application root directory and configure it to your needs.
55
59
56
60
## How to configure image to run my project ?
57
61
58
-
- You'll need to iterate over your application's dependency system packages, and required PHP Extensions; and add them to their respective locations in the image. (instructions below)
62
+
You'll need to iterate over your application's dependency system packages, and required PHP Extensions; and add them to their respective locations in the image.
63
+
64
+
1. Add System Dependencies and PHP Extensions your application depends on to the Image.
65
+
2. Port in any configuration changes you made for PHP.ini to the image, otherwise use the saint defaults.
66
+
3.`make build && make up` for development setup, `make deploy` to run the production variant.
Your application will be split into two components.
75
+
76
+
1.**The Webserver** -> Server Static Content and proxy dynamic requests to PHP-FPM over TCP, webserver also applies rate limiting, security headers... and whatever it is configured for.
77
+
2.**The PHP Process** -> PHP FPM process that will run you PHP Code.
78
+
79
+
> Other type of deployments such as a cron-job, or a supervised consumer can be achieved by overriding the default image CMD.
59
80
60
81
-----
82
+
61
83
# Requirements
62
84
63
85
-[Docker 20.05 or higher](https://docs.docker.com/install/)
64
-
-[Docker-Compose 3.5 or higher](https://docs.docker.com/compose/install/) (optional)
86
+
-[Docker-Compose 3.7 or higher](https://docs.docker.com/compose/install/) (optional)
65
87
- PHP >= 7 Application
66
88
67
89
# Setup
@@ -146,27 +168,45 @@ However, in an environment where CI/CD pipelines will build the image, they will
146
168
1. PHP `prod` Only Configuration `docker/conf/php/php-prod.ini`[🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/php/prod-php.ini)
147
169
2. PHP `dev` Only Configuration `docker/conf/php/php-dev.ini`[🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/php/dev-php.ini)
Nginx defaults are all defined in `docker/conf/nginx/` [🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/conf/nginx/)
179
+
In `docker/` directory there is `post-build` and `post-install` scripts that are used **to extend the image** and add extra behavior.
153
180
154
-
Nginx is pre-configured with:
155
-
1. HTTP, HTTPS, and HTTP2.
156
-
2. Rate limit (`rate=5r/s`)
157
-
3. Access & Error logs to `stdout/err`
158
-
4. Recommended Security Headers
159
-
5. Serving Static content with default cache `7d`
160
-
6. Metrics endpoint at `:8080/stub_status` from localhost only.
181
+
1. `post-build` command runs at the end of Image build.
182
+
183
+
Run as the last step during the image build. Are Often framework specific commands that generate optimized builds.
184
+
185
+
2. `pre-run` command runs **in runtime** before running the container main command
186
+
187
+
Runs before the container's CMD, but after the composer's post-install and post-autload-dump. Used for commands that needs to run at runtime before the application is started. Often are scripts that depends on other services or runtime parameters.
161
188
162
189
--------
163
190
164
191
# Misc Notes
165
192
- Your application [should log app logs to stdout.](https://stackoverflow.com/questions/38499825/symfony-logs-to-stdout-inside-docker-container). Read about [12factor/logs](https://12factor.net/logs)
166
-
- By default, `php-fpm` access & error logs are disabled as they're mirrored on `nginx`, this is so that `php-fpm` image will contain **only** application logs written by PHP.
167
-
- During Build, Image will run `composer dump-autoload` and `composer dump-env` to optimize for performance.
193
+
- By default, `php-fpm` access logs are disabled as they're mirrored on `nginx`, this is so that `php-fpm` image will contain **only** application logs written by PHP.
168
194
- In **production**, Image contains source-code, however, you must sync both `php-fpm` and `nginx` images so that they contain the same code.
169
195
196
+
197
+
--------
198
+
199
+
# FAQ
200
+
201
+
1. Why two containers instead of one ?
202
+
203
+
1. In containerized environment, you need to only run one process inside the container. This allows us to better instrument our application for many reasons like separation of health status, metrics, logs, etc.
204
+
205
+
2. Why `debian` based image not `alpine` ?
206
+
207
+
1. While a smaller image is very desired, and PHP image is infamous of being big. Alpine lacks a lot of packages (Available via `apk`) that a typical PHP would need. Some packages are not even available for alpine as they link to glibc not musl.
0 commit comments