commit aa207bb132417dac1f1c39640beb440d1edcc279 Author: William Date: Mon Feb 20 19:27:36 2023 +0100 Init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5be6d46 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM docker.io/alpine:latest + +RUN apk update && \ + apk add tini composer git nginx php-fpm && \ + adduser -D -g 'www' www && \ + mkdir /www && \ + chown -R www:www /var/lib/nginx && \ + chown -R www:www /www + +COPY ./nginx.conf /etc/nginx/nginx.conf +COPY ./entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["tini", "--", "/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cc9e7c --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# SamplePHPContainer + +Containing Nginx with FastCGI and Composer. + +# Usage + +## Build + +Clone the repo and build it locally + + docker build --no-cache -f ./Dockerfile --tag sample-php-container + +The container is now ready to be used, navigate to your project folder. + +## Packages + +This will install and or update any packages located in your composer file. + + docker run -dt -e UPDATE=1 -v ./:/www sample-php-container + +## Serving + +Nginx serves files from the `public` directory. Any files Nginx fails to find locally will be redirected to `index.php`. + + docker run -dt -v ./:/www -p 8080:8080 --name sample-php-container-name sample-php-container \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..369db04 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh +if [ "$UPDATE" = "1" ] +then + cd /www + composer update +else + nginx + /usr/sbin/php-fpm* + exec sleep infinity +fi \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..cf47c17 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,38 @@ +user www; +worker_processes 1; + +error_log stderr warn; +pid /var/run/nginx/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile on; + access_log off; + keepalive_timeout 3000; + + server_tokens off; + + server { + listen 8080; + root /www/public; + index index.php; + server_name localhost; + + error_page 404 /index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + try_files $uri = /; + fastcgi_pass 127.0.0.1:9000; + include fastcgi.conf; + } + } +} \ No newline at end of file