This commit is contained in:
William 2023-02-20 19:27:36 +01:00
commit aa207bb132
4 changed files with 86 additions and 0 deletions

13
Dockerfile Normal file
View File

@ -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"]

25
README.md Normal file
View File

@ -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

10
entrypoint.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if [ "$UPDATE" = "1" ]
then
cd /www
composer update
else
nginx
/usr/sbin/php-fpm*
exec sleep infinity
fi

38
nginx.conf Normal file
View File

@ -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;
}
}
}