Last active
February 9, 2022 02:03
-
-
Save felipecwb/9cf5cada0a56a156523e3aca5b39e51b to your computer and use it in GitHub Desktop.
Runit PHP & Nginx - one container - user level - output logginn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:3.8 | |
ENV USER app | |
ENV GROUP app | |
ENV WORKDIR /home/app | |
ENV PHPFPM_SOCK /tmp/php-fpm7.sock | |
# USER | |
RUN addgroup -g 1000 $GROUP \ | |
&& adduser -S -u 1000 -G $GROUP $USER | |
# installs | |
# RUNIT / NGINX / PHP | |
RUN apk add --update --no-cache \ | |
runit \ | |
\ | |
nginx \ | |
\ | |
php7 \ | |
php7-bz2 \ | |
php7-calendar \ | |
php7-ctype \ | |
php7-curl \ | |
php7-dom \ | |
php7-fpm \ | |
php7-gd \ | |
php7-iconv \ | |
php7-intl \ | |
php7-json \ | |
php7-mbstring \ | |
php7-opcache \ | |
php7-openssl \ | |
php7-pdo \ | |
php7-pdo_sqlite \ | |
php7-pdo_mysql \ | |
php7-pcntl \ | |
php7-phar \ | |
php7-posix \ | |
php7-session \ | |
php7-simplexml \ | |
php7-sockets \ | |
php7-sodium \ | |
php7-zip | |
# RUNIT CONFIG | |
RUN mkdir -p /etc/service/nginx \ | |
&& { \ | |
echo '#!/bin/sh'; \ | |
echo 'exec /usr/sbin/nginx || exit 1'; \ | |
} | tee /etc/service/nginx/run \ | |
&& chmod a+x /etc/service/nginx/run \ | |
\ | |
# php-fpm7 | |
&& mkdir -p /etc/service/php-fpm7 \ | |
&& { \ | |
echo '#!/bin/sh'; \ | |
echo 'exec /usr/sbin/php-fpm7 --nodaemonize --force-stderr || exit 1'; \ | |
} | tee /etc/service/php-fpm7/run \ | |
&& chmod a+x /etc/service/php-fpm7/run | |
# PHP CONFIG | |
RUN { \ | |
echo '[global]'; \ | |
echo 'error_log = /proc/self/fd/2'; \ | |
echo 'include=/etc/php7/php-fpm.d/*.conf'; \ | |
} | tee /etc/php7/php-fpm.conf \ | |
&& { \ | |
echo '[www]'; \ | |
echo "user = $USER"; \ | |
echo "group = $GROUP"; \ | |
echo "listen = $PHPFPM_SOCK"; \ | |
echo "listen.owner = $USER"; \ | |
echo "listen.group = $GROUP"; \ | |
echo 'listen.mode = 0666'; \ | |
echo 'pm = dynamic'; \ | |
echo 'pm.start_servers = 1'; \ | |
echo 'pm.max_children = 5'; \ | |
echo 'pm.min_spare_servers = 1'; \ | |
echo 'pm.max_spare_servers = 3'; \ | |
echo 'access.log = /proc/self/fd/2'; \ | |
echo 'catch_workers_output = yes'; \ | |
echo 'clear_env = no'; \ | |
echo 'php_admin_flag[log_errors] = on'; \ | |
echo 'php_admin_value[error_log] = /proc/self/fd/2'; \ | |
} | tee /etc/php7/php-fpm.d/www.conf | |
# NGINX CONFIG | |
RUN sed -i "s|user nginx|user $USER $GROUP|" /etc/nginx/nginx.conf \ | |
&& sed -i "s|/var/log/nginx/access.log|stdout|" /etc/nginx/nginx.conf \ | |
&& sed -i "s|/var/log/nginx/error.log|stderr|" /etc/nginx/nginx.conf \ | |
&& { \ | |
echo 'pid /tmp/nginx.pid;'; \ | |
echo 'daemon off;'; \ | |
} | tee -a /etc/nginx/nginx.conf \ | |
&& { \ | |
echo 'server {'; \ | |
echo ' listen 8080;'; \ | |
echo ' listen [::]:8080;'; \ | |
echo " root ${WORKDIR}/public;"; \ | |
echo ' index index.html index.php;'; \ | |
\ | |
echo ' location / {'; \ | |
echo ' try_files $uri /index.php$is_args$args;'; \ | |
echo ' }'; \ | |
\ | |
echo ' location ~ \.php$ {'; \ | |
echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;'; \ | |
echo " fastcgi_pass unix:${PHPFPM_SOCK};"; \ | |
echo ' fastcgi_index index.php;'; \ | |
echo ' fastcgi_param HTTP_PROXY "";'; \ | |
echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'; \ | |
echo ' include fastcgi_params;'; \ | |
echo ' }'; \ | |
echo '}'; \ | |
} | tee /etc/nginx/conf.d/default.conf | |
WORKDIR $WORKDIR | |
COPY --chown=$USER:$GROUP . $WORKDIR | |
EXPOSE 8080 | |
CMD ["/sbin/runsvdir", "/etc/service"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment