-
-
Save matthewpalmer/741dc7a4c418318f85f2fa8da7de2ea1 to your computer and use it in GitHub Desktop.
# Create a pod containing the PHP-FPM application (my-php-app) | |
# and nginx, each mounting the `shared-files` volume to their | |
# respective /var/www/html directories. | |
kind: Pod | |
apiVersion: v1 | |
metadata: | |
name: phpfpm-nginx-example | |
spec: | |
volumes: | |
# Create the shared files volume to be used in both pods | |
- name: shared-files | |
emptyDir: {} | |
# Add the ConfigMap we declared above as a volume for the pod | |
- name: nginx-config-volume | |
configMap: | |
name: nginx-config | |
containers: | |
# Our PHP-FPM application | |
- image: my-php-app:1.0.0 | |
name: app | |
volumeMounts: | |
- name: shared-files | |
mountPath: /var/www/html | |
# Important! After this container has started, the PHP files | |
# in our Docker image aren't in the shared volume. We need to | |
# get them into the shared volume. If we tried to write directly | |
# to this volume from our Docker image the files wouldn't appear | |
# in the nginx container. | |
# | |
# So, after the container has started, copy the PHP files from this | |
# container's local filesystem (/app -- added via the Docker image) | |
# to the shared volume, which is mounted at /var/www/html. | |
lifecycle: | |
postStart: | |
exec: | |
command: ["/bin/sh", "-c", "cp -r /app/. /var/www/html"] | |
# Our nginx container, which uses the configuration declared above, | |
# along with the files shared with the PHP-FPM app. | |
- image: nginx:1.7.9 | |
name: nginx | |
volumeMounts: | |
- name: shared-files | |
mountPath: /var/www/html | |
- name: nginx-config-volume | |
mountPath: /etc/nginx/nginx.conf | |
subPath: nginx.conf |
For the record, I have since moved towards bundling PHP + the web server in the same image.
I believe I followed TrafeX/docker-php-nginx as an example.
For the record, I have since moved towards bundling PHP + the web server in the same image.
I believe I followed TrafeX/docker-php-nginx as an example.
Thanks for sharing this. I will make use of it :)
Same, that looks like a mature and well implemented image @lstellway.
One of those times I really wish Github Gists had reactions. That way we could just react with 👍 or whatever instead of spamming the thread. 😁
Oh my God, colleagues, it's not safe to transfer files with source codes, maybe this is your case, but if you use fast-cgi, it's better to proxy it through upstream;
like this:
server_name localhost;
location / {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /srv/www/public/index.php;
fastcgi_param PATH_INFO $uri;
}
At the same time, your container with nginx should not have any source code, at most some static in the form of pictures...
Next up to test/validate your cluster, do some pre-prod testing. Scale it up and do some load testing! Pound it with a bunch of traffic (e.g. Gatling). Then, maybe delete a line of code on one of the containers, see how easy it is for you to see/diagnose errors when only some of your requests are failing. When your new persistent storage is setup, put a 3mb
.jpg
on one of the containers in the shared volume and see if it’s available on all the others and/or how long it takes to sync.… good luck!