From 970122d167173a219e56c9c28390b0d38dd0e662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E5=B0=91=E6=B3=A2?= <756684177@qq.com> Date: Fri, 25 Jun 2021 11:26:04 +0800 Subject: [PATCH] init --- .gitignore | 1 + Dockerfile | 50 +++++++++++++++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++++++ README.md | 30 +++++++++++++++++++++++-- config/php.ini | 2 ++ config/supervisord.conf | 14 ++++++++++++ 6 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 config/php.ini create mode 100644 config/supervisord.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc8a670 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f766f86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM php:7.4.14-cli-alpine3.13 +LABEL Maintainer="weijer " \ + Description="Webman Lightweight container with PHP 7.4 based on Alpine Linux." + +# Add basics first +RUN apk update && apk upgrade && apk add \ + bash curl ca-certificates openssl openssh git nano libxml2-dev tzdata icu-dev openntpd libedit-dev libzip-dev libjpeg-turbo-dev libpng-dev freetype-dev \ + autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c pcre-dev openssl-dev libffi-dev libressl-dev libevent-dev zlib-dev libtool automake \ + supervisor + +RUN docker-php-ext-install soap zip pcntl sockets intl exif opcache pdo_mysql mysqli bcmath calendar gd + +RUN pecl install -o -f redis \ + && pecl install -o -f event \ + && docker-php-ext-enable redis \ + && echo extension=event.so >> /usr/local/etc/php/conf.d/docker-php-ext-sockets.ini \ + && pecl clear-cache + +RUN php -m + +# Add Composer +RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer + +# Configure PHP +COPY config/php.ini /usr/local/etc/php/conf.d/zzz_custom.ini + +# Configure supervisord +COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# Make sure files/folders needed by the processes are accessable when they run under the nobody user +RUN chown -R nobody.nobody /run + +# Setup document root +RUN mkdir -p /app + +# Make the document root a volume +VOLUME /app + +#echo " > /usr/local/etc/php/conf.d/phalcon.ini +# Switch to use a non-root user from here on +USER root + +# Add application +WORKDIR /app + +# Expose the port nginx is reachable on +EXPOSE 8080 + +# Let supervisord start nginx & php-fpm +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2b4dc00 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Tim de Pater + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 8c2b849..4517bbe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ -# docker-php-nginx-7.4 -docker-php-nginx-7.4 +# Docker PHP-FPM 7.4 & Nginx 1.16 on Alpine Linux +Example PHP-FPM 7.4 & Nginx 1.16 setup for Docker, build on [Alpine Linux](http://www.alpinelinux.org/). +The image is only +/- 35MB large. + + +* Built on the lightweight and secure Alpine Linux distribution +* Very small Docker image size (+/-35MB) +* Uses PHP 7.4 for better performance, lower cpu usage & memory footprint +* Optimized for 100 concurrent users +* Optimized to only use resources when there's traffic (by using PHP-FPM's ondemand PM) +* The servers Nginx, PHP-FPM and supervisord run under a non-privileged user (nobody) to make it more secure +* The logs of all the services are redirected to the output of the Docker container (visible with `docker logs -f `) +* Follows the KISS principle (Keep It Simple, Stupid) to make it easy to understand and adjust the image + + +## Usage + +Start the Docker container: + +docker run -p 80:8080 gsviec/nginx-php:7.4 + +See the PHP info on http://localhost, or the static html page on http://localhost/test.html + +Or mount your own code to be served by PHP-FPM & Nginx + +``` +docker run -p 80:8080 -v ~/my-codebase:/var/www/html gsviec/nginx-php:7.4 +``` diff --git a/config/php.ini b/config/php.ini new file mode 100644 index 0000000..7bb1be5 --- /dev/null +++ b/config/php.ini @@ -0,0 +1,2 @@ +[Date] +date.timezone="UTC" diff --git a/config/supervisord.conf b/config/supervisord.conf new file mode 100644 index 0000000..8cc3707 --- /dev/null +++ b/config/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true +logfile=/dev/null +logfile_maxbytes=0 +pidfile=/run/supervisord.pid + +[program:webman] +command=php /app/start.php start -d +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0