diff --git a/README.md b/README.md index e62b982..b7b9f70 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,77 @@ # Docker PHP-FPM & Nginx base on Alpine Linux -Simple docker image for PHP development +Simple docker image for Magento development + +### Why should use this image + +- Built on the lightweight and + secure [Alpine Linux](https://www.alpinelinux.org/) distribution +- Multi-platform, supporting AMD4, ARMv6, ARMv7, ARM64 +- Use [runit](http://smarden.org/runit/) instead + of [supervisor](http://supervisord.org/) +- Very small Docker image size + +### PHP version support + +- [x] PHP 7.2 +- [x] PHP 7.4 +- [x] PHP 8.0 +- [x] PHP 8.1 (recommend usage) +- [ ] PHP 8.2 (todo) ### How to use -- First, build image +- Build image ```shell -./build 74 # Build docker php image for php 7.4 -./build 80 # Build docker php image for php 8.0 -./build 81 # Build docker php image for php 8.1 +./build php7.2 # Build image with php 7.2 +./build php7.4 # Build image with php 7.4 +./build php8.0 # Build image with php 8.0 +./build php8.1 # Build image with php 8.1 ``` - Mount your code to be served with container ```shell -docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/php:74 -docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/php:80 -docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/php:81 +docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/magento:php7.4 +docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/magento:php8.0 +docker run --name=app -v /path/to/project:/var/www/html -p 80:80 pnlinh/magento:php8.1 +``` + +- With docker-compose + +``` +version: '3.4' + +services: + app: + image: pnlinh/magento:php8.1 + hostname: magento-app + container_name: magento-app + ports: + - "80:80" + volumes: + - .:/var/www/html + networks: + - localnet ``` - See PHP version info ```shell -docker run --name=app --rm -p 80:80 pnlinh/php:74 -docker run --name=app --rm -p 80:80 pnlinh/php:80 -docker run --name=app --rm -p 80:80 pnlinh/php:81 +docker run --name=app --rm -p 80:80 pnlinh/magento:php7.4 +docker run --name=app --rm -p 80:80 pnlinh/magento:php8.0 +docker run --name=app --rm -p 80:80 pnlinh/magento:php8.1 ``` ![image](https://user-images.githubusercontent.com/26193890/164198187-743e3585-1379-4d06-a2d5-34330b17d060.png) -### References - - https://github.com/TrafeX/docker-php-nginx +### Useful images + +- PHP/Laravel: https://github.com/pnlinh/docker-php +- Symfony: https://github.com/pnlinh/docker-php/tree/feature/symfony + +### References + +- https://github.com/TrafeX/docker-php-nginx +- https://bolshov.online/docker/2020/11/18/runit-vs-supervisor diff --git a/build b/build index 4af8a4f..00d4f00 100755 --- a/build +++ b/build @@ -1,11 +1,11 @@ #!/usr/bin/env bash -VERSIONS=("72" "74" "80" "81") -IMAGE="pnlinh/php" +TAGS=("php7.2" "php7.4" "php8.0" "php8.1") +IMAGE="pnlinh/magento" # shellcheck disable=SC2199 # shellcheck disable=SC2076 -if [[ ! " ${VERSIONS[@]} " =~ " $1 " ]]; then +if [[ ! " ${TAGS[@]} " =~ " $1 " ]]; then echo "Invalid version." exit 1 fi @@ -17,7 +17,7 @@ if [ $# -gt 0 ]; then echo "All done." exit 0 fi - docker build --no-cache -f "php$1".Dockerfile . -t ${IMAGE}:"$1" + docker build --no-cache -f "$1".Dockerfile . -t ${IMAGE}:"$1" else echo "Nothing to build." fi diff --git a/config/72/boot.sh b/config/72/boot.sh new file mode 100644 index 0000000..835a26d --- /dev/null +++ b/config/72/boot.sh @@ -0,0 +1,39 @@ +#!/bin/sh +shutdown() { + echo "shutting down container" + + # first shutdown any service started by runit + for _srv in $(ls -1 /etc/service); do + sv force-stop ${_srv} + done + + # shutdown runsvdir command + kill -HUP ${PID} + wait ${PID} + + # give processes time to stop + sleep 0.5 + + # kill any other processes still running in the container + for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do + timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid" + done + exit +} + +exec env - PATH=$PATH runsvdir -P /etc/service & + +PID=$! +echo "Started runsvdir, PID is $PID" +echo "wait for processes to start...." + +sleep 5 +for _srv in $(ls -1 /etc/service); do + sv status ${_srv} +done + +# catch shutdown signals +trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT +wait ${PID} + +shutdown \ No newline at end of file diff --git a/config/72/fpm-pool.conf b/config/72/fpm-pool.conf index 303b3cf..4cfa684 100644 --- a/config/72/fpm-pool.conf +++ b/config/72/fpm-pool.conf @@ -3,6 +3,10 @@ error_log = /dev/stderr [www] + +user = www +group = www + ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on @@ -13,7 +17,7 @@ error_log = /dev/stderr ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /run/php-fpm.sock +listen = 127.0.0.1:9000 ; Enable status page pm.status_path = /fpm-status diff --git a/config/72/nginx.conf b/config/72/nginx.conf index 43b6811..d66e266 100644 --- a/config/72/nginx.conf +++ b/config/72/nginx.conf @@ -39,7 +39,7 @@ http { tcp_nodelay on; absolute_redirect off; - root /var/www/html/public; + root /var/www/html; index index.php index.html; location / { @@ -58,7 +58,7 @@ http { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; diff --git a/config/72/nginx.run b/config/72/nginx.run new file mode 100644 index 0000000..b6babfa --- /dev/null +++ b/config/72/nginx.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run nginx +exec 2>&1 +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/config/72/php.run b/config/72/php.run new file mode 100644 index 0000000..95c8f15 --- /dev/null +++ b/config/72/php.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run php-fpm +exec 2>&1 +exec php-fpm7 -F diff --git a/config/72/supervisord.conf b/config/72/supervisord.conf deleted file mode 100644 index edd5207..0000000 --- a/config/72/supervisord.conf +++ /dev/null @@ -1,23 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/run/supervisord.pid - -[program:php-fpm] -command=php-fpm7 -F -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 - -[program:nginx] -command=nginx -g 'daemon off;' -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 diff --git a/config/74/boot.sh b/config/74/boot.sh new file mode 100644 index 0000000..835a26d --- /dev/null +++ b/config/74/boot.sh @@ -0,0 +1,39 @@ +#!/bin/sh +shutdown() { + echo "shutting down container" + + # first shutdown any service started by runit + for _srv in $(ls -1 /etc/service); do + sv force-stop ${_srv} + done + + # shutdown runsvdir command + kill -HUP ${PID} + wait ${PID} + + # give processes time to stop + sleep 0.5 + + # kill any other processes still running in the container + for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do + timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid" + done + exit +} + +exec env - PATH=$PATH runsvdir -P /etc/service & + +PID=$! +echo "Started runsvdir, PID is $PID" +echo "wait for processes to start...." + +sleep 5 +for _srv in $(ls -1 /etc/service); do + sv status ${_srv} +done + +# catch shutdown signals +trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT +wait ${PID} + +shutdown \ No newline at end of file diff --git a/config/74/fpm-pool.conf b/config/74/fpm-pool.conf index eed0323..a37cbdf 100644 --- a/config/74/fpm-pool.conf +++ b/config/74/fpm-pool.conf @@ -17,7 +17,7 @@ group = www ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /run/php-fpm.sock +listen = 127.0.0.1:9000 ; Enable status page pm.status_path = /fpm-status diff --git a/config/74/nginx.conf b/config/74/nginx.conf index 43b6811..b90e495 100644 --- a/config/74/nginx.conf +++ b/config/74/nginx.conf @@ -39,7 +39,7 @@ http { tcp_nodelay on; absolute_redirect off; - root /var/www/html/public; + root /var/www/html; index index.php index.html; location / { @@ -54,11 +54,11 @@ http { root /var/lib/nginx/html; } - # Pass the PHP scripts to PHP-FPM listening on php-fpm.sock + # Pass the PHP scripts to PHP-FPM listening on 127.0.0.1:9000 location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; @@ -82,7 +82,7 @@ http { deny all; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; - fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_pass 127.0.0.1:9000; } } diff --git a/config/74/nginx.run b/config/74/nginx.run new file mode 100644 index 0000000..b6babfa --- /dev/null +++ b/config/74/nginx.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run nginx +exec 2>&1 +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/config/74/php.run b/config/74/php.run new file mode 100644 index 0000000..95c8f15 --- /dev/null +++ b/config/74/php.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run php-fpm +exec 2>&1 +exec php-fpm7 -F diff --git a/config/74/supervisord.conf b/config/74/supervisord.conf deleted file mode 100644 index edd5207..0000000 --- a/config/74/supervisord.conf +++ /dev/null @@ -1,23 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/run/supervisord.pid - -[program:php-fpm] -command=php-fpm7 -F -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 - -[program:nginx] -command=nginx -g 'daemon off;' -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 diff --git a/config/80/boot.sh b/config/80/boot.sh new file mode 100644 index 0000000..835a26d --- /dev/null +++ b/config/80/boot.sh @@ -0,0 +1,39 @@ +#!/bin/sh +shutdown() { + echo "shutting down container" + + # first shutdown any service started by runit + for _srv in $(ls -1 /etc/service); do + sv force-stop ${_srv} + done + + # shutdown runsvdir command + kill -HUP ${PID} + wait ${PID} + + # give processes time to stop + sleep 0.5 + + # kill any other processes still running in the container + for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do + timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid" + done + exit +} + +exec env - PATH=$PATH runsvdir -P /etc/service & + +PID=$! +echo "Started runsvdir, PID is $PID" +echo "wait for processes to start...." + +sleep 5 +for _srv in $(ls -1 /etc/service); do + sv status ${_srv} +done + +# catch shutdown signals +trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT +wait ${PID} + +shutdown \ No newline at end of file diff --git a/config/80/fpm-pool.conf b/config/80/fpm-pool.conf index 4be2061..a37cbdf 100644 --- a/config/80/fpm-pool.conf +++ b/config/80/fpm-pool.conf @@ -3,6 +3,10 @@ error_log = /dev/stderr [www] + +user = www +group = www + ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on @@ -13,7 +17,7 @@ error_log = /dev/stderr ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /run/php-fpm.sock +listen = 127.0.0.1:9000 ; Enable status page pm.status_path = /fpm-status diff --git a/config/80/nginx.conf b/config/80/nginx.conf index c45c414..db486ad 100644 --- a/config/80/nginx.conf +++ b/config/80/nginx.conf @@ -39,7 +39,7 @@ http { tcp_nodelay on; absolute_redirect off; - root /var/www/html/public; + root /var/www/html; index index.php index.html; location / { @@ -58,7 +58,7 @@ http { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; diff --git a/config/80/nginx.run b/config/80/nginx.run new file mode 100644 index 0000000..b6babfa --- /dev/null +++ b/config/80/nginx.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run nginx +exec 2>&1 +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/config/80/php.run b/config/80/php.run new file mode 100644 index 0000000..6fa4ca5 --- /dev/null +++ b/config/80/php.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run php-fpm +exec 2>&1 +exec php-fpm8 -F diff --git a/config/80/supervisord.conf b/config/80/supervisord.conf deleted file mode 100644 index 216a387..0000000 --- a/config/80/supervisord.conf +++ /dev/null @@ -1,23 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/run/supervisord.pid - -[program:php-fpm] -command=php-fpm8 -F -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 - -[program:nginx] -command=nginx -g 'daemon off;' -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 diff --git a/config/81/boot.sh b/config/81/boot.sh new file mode 100644 index 0000000..835a26d --- /dev/null +++ b/config/81/boot.sh @@ -0,0 +1,39 @@ +#!/bin/sh +shutdown() { + echo "shutting down container" + + # first shutdown any service started by runit + for _srv in $(ls -1 /etc/service); do + sv force-stop ${_srv} + done + + # shutdown runsvdir command + kill -HUP ${PID} + wait ${PID} + + # give processes time to stop + sleep 0.5 + + # kill any other processes still running in the container + for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do + timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid" + done + exit +} + +exec env - PATH=$PATH runsvdir -P /etc/service & + +PID=$! +echo "Started runsvdir, PID is $PID" +echo "wait for processes to start...." + +sleep 5 +for _srv in $(ls -1 /etc/service); do + sv status ${_srv} +done + +# catch shutdown signals +trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT +wait ${PID} + +shutdown \ No newline at end of file diff --git a/config/81/fpm-pool.conf b/config/81/fpm-pool.conf index 4be2061..a37cbdf 100644 --- a/config/81/fpm-pool.conf +++ b/config/81/fpm-pool.conf @@ -3,6 +3,10 @@ error_log = /dev/stderr [www] + +user = www +group = www + ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on @@ -13,7 +17,7 @@ error_log = /dev/stderr ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /run/php-fpm.sock +listen = 127.0.0.1:9000 ; Enable status page pm.status_path = /fpm-status diff --git a/config/81/nginx.conf b/config/81/nginx.conf index c45c414..db486ad 100644 --- a/config/81/nginx.conf +++ b/config/81/nginx.conf @@ -39,7 +39,7 @@ http { tcp_nodelay on; absolute_redirect off; - root /var/www/html/public; + root /var/www/html; index index.php index.html; location / { @@ -58,7 +58,7 @@ http { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; diff --git a/config/81/nginx.run b/config/81/nginx.run new file mode 100644 index 0000000..b6babfa --- /dev/null +++ b/config/81/nginx.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run nginx +exec 2>&1 +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/config/81/php.run b/config/81/php.run new file mode 100644 index 0000000..ff52a88 --- /dev/null +++ b/config/81/php.run @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# pipe stderr to stdout and run php-fpm +exec 2>&1 +exec php-fpm81 -F diff --git a/config/81/supervisord.conf b/config/81/supervisord.conf deleted file mode 100644 index 77bda1a..0000000 --- a/config/81/supervisord.conf +++ /dev/null @@ -1,23 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/run/supervisord.pid - -[program:php-fpm] -command=php-fpm81 -F -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 - -[program:nginx] -command=nginx -g 'daemon off;' -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=false -startretries=0 diff --git a/php72.Dockerfile b/php7.2.Dockerfile similarity index 80% rename from php72.Dockerfile rename to php7.2.Dockerfile index e5bb2db..f2e4c0d 100644 --- a/php72.Dockerfile +++ b/php7.2.Dockerfile @@ -36,12 +36,10 @@ RUN apk add --no-cache \ php7-soap \ php7-common \ php7-sqlite3 \ + php7-session \ curl \ nginx \ - vim \ - nano \ - supervisor \ - git + runit # Install XDebug @@ -49,7 +47,7 @@ RUN apk add --no-cache \ RUN cp /usr/bin/php7 /usr/bin/php # Install Composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer +COPY --from=composer/composer:2-bin /composer /usr/bin/composer # Configure nginx COPY config/72/nginx.conf /etc/nginx/nginx.conf @@ -61,8 +59,8 @@ RUN rm /etc/nginx/conf.d/default.conf COPY config/72/fpm-pool.conf /etc/php7/php-fpm.d/www.conf COPY config/72/php.ini /etc/php7/conf.d/custom.ini -# Configure supervisord -COPY config/72/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +# Configure runit boot script +COPY config/72/boot.sh /sbin/boot.sh # Make sure files/folders needed by the processes are accessable when they run under the www user ARG nginxUID=1000 @@ -70,23 +68,27 @@ ARG nginxGID=1000 RUN adduser -D -u ${nginxUID} -g ${nginxGID} -s /bin/sh www && \ mkdir -p /var/www/html && \ + mkdir -p /var/www/html/tmp && \ mkdir -p /var/cache/nginx && \ chown -R www:www /var/www/html && \ chown -R www:www /run && \ chown -R www:www /var/lib/nginx && \ chown -R www:www /var/log/nginx -# Switch to use a www user from here on -USER www +COPY config/72/nginx.run /etc/service/nginx/run +COPY config/72/php.run /etc/service/php/run + +RUN chmod +x /etc/service/nginx/run \ + && chmod +x /etc/service/php/run # Add application -COPY --chown=www src/ /var/www/html/public +COPY --chown=www src/ /var/www/html # Expose the port nginx is reachable on EXPOSE 80 -# Let supervisord start nginx & php-fpm -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +# Let boot start nginx & php-fpm +CMD ["sh", "/sbin/boot.sh"] # Configure a healthcheck to validate that everything is up & running HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:80/fpm-ping diff --git a/php74.Dockerfile b/php7.4.Dockerfile similarity index 74% rename from php74.Dockerfile rename to php7.4.Dockerfile index 82b871f..ca0d0d1 100644 --- a/php74.Dockerfile +++ b/php7.4.Dockerfile @@ -17,6 +17,7 @@ RUN apk add --no-cache \ php7-mbstring \ php7-openssl \ php7-pdo_pgsql \ + php7-pdo_mysql \ php7-curl \ php7-pdo \ php7-tokenizer \ @@ -29,20 +30,10 @@ RUN apk add --no-cache \ php7-xmlreader \ php7-zip \ php7-simplexml \ - php7-redis \ - php7-pdo_mysql \ - php7-pdo_pgsql \ - php7-pdo_sqlite \ - php7-soap \ - php7-pecl-apcu \ - php7-common \ - php7-sqlite3 \ + php7-session \ curl \ nginx \ - vim \ - nano \ - supervisor \ - git + runit # Install XDebug @@ -50,7 +41,7 @@ RUN apk add --no-cache \ RUN cp /usr/bin/php7 /usr/bin/php # Install Composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer +COPY --from=composer/composer:2-bin /composer /usr/bin/composer # Configure nginx COPY config/74/nginx.conf /etc/nginx/nginx.conf @@ -59,8 +50,8 @@ COPY config/74/nginx.conf /etc/nginx/nginx.conf COPY config/74/fpm-pool.conf /etc/php7/php-fpm.d/www.conf COPY config/74/php.ini /etc/php7/conf.d/custom.ini -# Configure supervisord -COPY config/74/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +# Configure runit boot script +COPY config/74/boot.sh /sbin/boot.sh # Make sure files/folders needed by the processes are accessable when they run under the www user ARG nginxUID=1000 @@ -68,23 +59,27 @@ ARG nginxGID=1000 RUN adduser -D -u ${nginxUID} -g ${nginxGID} -s /bin/sh www && \ mkdir -p /var/www/html && \ + mkdir -p /var/www/html/tmp && \ mkdir -p /var/cache/nginx && \ chown -R www:www /var/www/html && \ chown -R www:www /run && \ chown -R www:www /var/lib/nginx && \ chown -R www:www /var/log/nginx -# Switch to use a www user from here on -USER www +COPY config/74/nginx.run /etc/service/nginx/run +COPY config/74/php.run /etc/service/php/run + +RUN chmod +x /etc/service/nginx/run \ + && chmod +x /etc/service/php/run # Add application -COPY --chown=www src/ /var/www/html/public +COPY --chown=www src/ /var/www/html # Expose the port nginx is reachable on EXPOSE 80 -# Let supervisord start nginx & php-fpm -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +# Let boot start nginx & php-fpm +CMD ["sh", "/sbin/boot.sh"] # Configure a healthcheck to validate that everything is up & running HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:80/fpm-ping diff --git a/php80.Dockerfile b/php8.0.Dockerfile similarity index 79% rename from php80.Dockerfile rename to php8.0.Dockerfile index a04d164..61cd6a5 100644 --- a/php80.Dockerfile +++ b/php8.0.Dockerfile @@ -37,12 +37,10 @@ RUN apk add --no-cache \ php8-pecl-apcu \ php8-common \ php8-sqlite3 \ + php8-session \ curl \ nginx \ - vim \ - nano \ - supervisor \ - git + runit # Install XDebug @@ -50,7 +48,7 @@ RUN apk add --no-cache \ RUN cp /usr/bin/php8 /usr/bin/php # Install Composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer +COPY --from=composer/composer:2-bin /composer /usr/bin/composer # Configure nginx COPY config/80/nginx.conf /etc/nginx/nginx.conf @@ -59,8 +57,8 @@ COPY config/80/nginx.conf /etc/nginx/nginx.conf COPY config/80/fpm-pool.conf /etc/php8/php-fpm.d/www.conf COPY config/80/php.ini /etc/php8/conf.d/custom.ini -# Configure supervisord -COPY config/80/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +# Configure runit boot script +COPY config/80/boot.sh /sbin/boot.sh # Make sure files/folders needed by the processes are accessable when they run under the www user ARG nginxUID=1000 @@ -68,23 +66,27 @@ ARG nginxGID=1000 RUN adduser -D -u ${nginxUID} -g ${nginxGID} -s /bin/sh www && \ mkdir -p /var/www/html && \ + mkdir -p /var/www/html/tmp && \ mkdir -p /var/cache/nginx && \ chown -R www:www /var/www/html && \ chown -R www:www /run && \ chown -R www:www /var/lib/nginx && \ chown -R www:www /var/log/nginx -# Switch to use a www user from here on -USER www +COPY config/80/nginx.run /etc/service/nginx/run +COPY config/80/php.run /etc/service/php/run + +RUN chmod +x /etc/service/nginx/run \ + && chmod +x /etc/service/php/run # Add application -COPY --chown=www src/ /var/www/html/public +COPY --chown=www src/ /var/www/html # Expose the port nginx is reachable on EXPOSE 80 -# Let supervisord start nginx & php-fpm -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +# Let boot start nginx & php-fpm +CMD ["sh", "/sbin/boot.sh"] # Configure a healthcheck to validate that everything is up & running HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:80/fpm-ping diff --git a/php81.Dockerfile b/php8.1.Dockerfile similarity index 79% rename from php81.Dockerfile rename to php8.1.Dockerfile index a59ff79..072265d 100644 --- a/php81.Dockerfile +++ b/php8.1.Dockerfile @@ -37,12 +37,10 @@ RUN apk add --no-cache \ php81-pecl-apcu \ php81-common \ php81-sqlite3 \ + php81-session \ curl \ nginx \ - vim \ - nano \ - supervisor \ - git + runit # Install XDebug @@ -50,7 +48,7 @@ RUN apk add --no-cache \ RUN cp /usr/bin/php81 /usr/bin/php # Install Composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer +COPY --from=composer/composer:2-bin /composer /usr/bin/composer # Configure nginx COPY config/81/nginx.conf /etc/nginx/nginx.conf @@ -59,8 +57,8 @@ COPY config/81/nginx.conf /etc/nginx/nginx.conf COPY config/81/fpm-pool.conf /etc/php81/php-fpm.d/www.conf COPY config/81/php.ini /etc/php81/conf.d/custom.ini -# Configure supervisord -COPY config/81/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +# Configure runit boot script +COPY config/81/boot.sh /sbin/boot.sh # Make sure files/folders needed by the processes are accessable when they run under the www user ARG nginxUID=1000 @@ -68,23 +66,27 @@ ARG nginxGID=1000 RUN adduser -D -u ${nginxUID} -g ${nginxGID} -s /bin/sh www && \ mkdir -p /var/www/html && \ + mkdir -p /var/www/html/tmp && \ mkdir -p /var/cache/nginx && \ chown -R www:www /var/www/html && \ chown -R www:www /run && \ chown -R www:www /var/lib/nginx && \ chown -R www:www /var/log/nginx -# Switch to use a www user from here on -USER www +COPY config/81/nginx.run /etc/service/nginx/run +COPY config/81/php.run /etc/service/php/run + +RUN chmod +x /etc/service/nginx/run \ + && chmod +x /etc/service/php/run # Add application -COPY --chown=www src/ /var/www/html/public +COPY --chown=www src/ /var/www/html # Expose the port nginx is reachable on EXPOSE 80 -# Let supervisord start nginx & php-fpm -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +# Let boot start nginx & php-fpm +CMD ["sh", "/sbin/boot.sh"] # Configure a healthcheck to validate that everything is up & running HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:80/fpm-ping