Created
October 26, 2020 11:57
-
-
Save mohammad-fouladgar/1ca7c8c30bd201c3a67df49da32bb346 to your computer and use it in GitHub Desktop.
PHP-dockerize
This file contains hidden or 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
#/bin/sh | |
cat >/usr/local/etc/php-fpm.d/www.conf <<EOF | |
[www] | |
user = nginx | |
group = nginx | |
listen = /run/php7.4-fpm.sock | |
listen.mode = 0600 | |
listen.owner = nginx | |
listen.group = nginx | |
pm = dynamic | |
pm.max_children = 40000 | |
pm.start_servers = 100 | |
pm.min_spare_servers = 100 | |
pm.max_spare_servers = 500 | |
pm.max_requests = 500 | |
pm.status_path = /status | |
ping.path = /ping | |
ping.response = pong | |
EOF | |
cat >/usr/local/etc/php-fpm.d/zz-docker.conf <<EOF | |
[global] | |
daemonize = no | |
EOF | |
cat >/etc/nginx/nginx.conf <<'EOF' | |
worker_processes auto; | |
user nginx; | |
pid /run/nginx.pid; | |
daemon off; | |
pcre_jit on; | |
error_log /proc/self/fd/2; | |
include /etc/nginx/modules/*.conf; | |
events { | |
worker_connections 12000; | |
multi_accept on; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
server_tokens off; | |
keepalive_timeout 65; | |
sendfile on; | |
tcp_nodelay on; | |
tcp_nopush on; | |
gzip_vary on; | |
gzip on; | |
map $request_uri $request_uri_path { | |
"~^(?P<path>[^?]*)(\?.*)?$" $path; | |
} | |
include /etc/nginx/conf.d/*.conf; | |
} | |
EOF | |
cat >/etc/nginx/conf.d/default.conf <<EOF | |
server { | |
listen 80; | |
server_name localhost; | |
charset utf-8; | |
root /var/www/public; | |
index index.php index.html index.htm; | |
location / { | |
try_files \$uri \$uri/ /index.php?\$query_string; | |
} | |
location ~ \.php$ { | |
include fastcgi.conf; | |
fastcgi_pass unix:/run/php7.4-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location ~ /.well-known { | |
allow all; | |
} | |
error_page 404 /index.php; | |
} | |
EOF | |
cat >/etc/supervisor.d/nginx.ini <<EOF | |
[program:nginx] | |
command=/usr/sbin/nginx | |
autostart=true | |
autorestart=true | |
stdout_logfile=/dev/stdout | |
stderr_logfile=/dev/stderr | |
stdout_logfile_maxbytes=0 | |
stderr_logfile_maxbytes=0 | |
EOF | |
cat >/etc/supervisor.d/php-fpm.ini <<EOF | |
[program:php-fpm] | |
command=/usr/local/sbin/php-fpm | |
autostart=true | |
autorestart=true | |
stdout_logfile=/dev/stdout | |
stderr_logfile=/dev/stderr | |
stdout_logfile_maxbytes=0 | |
stderr_logfile_maxbytes=0 | |
EOF | |
sed -i 's/;nodaemon=false/nodaemon=true/' /etc/supervisord.conf | |
sed -i 's/;pidfile=\/run\/supervisord.pid/pidfile=\/run\/supervisord.pid/' /etc/supervisord.conf | |
#cat > /etc/supervisord.conf<<EOF | |
#[unix_http_server] | |
#file=/var/run/supervisor.sock ; (the path to the socket file) | |
#chmod=0700 ; sockef file mode (default 0700) | |
#[supervisord] | |
#nodaemon=true | |
#[rpcinterface:supervisor] | |
#supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | |
#[supervisorctl] | |
#serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket | |
#[include] | |
#files = /etc/supervisor/conf.d/*.conf | |
#EOF | |
supervisord -c /etc/supervisord.conf |
This file contains hidden or 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
# | |
#-------------------------------------------------------------------------- | |
# Image Setup | |
#-------------------------------------------------------------------------- | |
# | |
FROM php:7.4.11-fpm-alpine | |
LABEL maintainer="Fouladgar < [email protected] >" | |
ENV COMPOSER_HOME=/var/www | |
RUN apk add --update --virtual build_deps bash gcc g++ autoconf make libssh2-dev pcre-dev libjpeg-turbo-dev libpng-dev freetype-dev curl-dev libxml2-dev readline-dev libedit-dev && \ | |
apk add git openssh-client freetype libpng libjpeg-turbo libmcrypt libzip-dev nodejs npm supervisor nginx ffmpeg nano && \ | |
mkdir -p /etc/supervisor.d/ | |
RUN docker-php-source extract && \ | |
docker-php-ext-install -j$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) gd \ | |
bcmath mysqli opcache pdo_mysql soap zip pcntl && \ | |
pecl install redis && \ | |
docker-php-ext-enable redis && \ | |
curl -sS "https://getcomposer.org/installer" | php && \ | |
mv composer.phar /usr/local/bin/composer && \ | |
docker-php-source delete && \ | |
chown nginx:nginx /var/www/ && \ | |
apk del build_deps && \ | |
rm -rf /var/cache/apk/* && \ | |
rm -rf /tmp/* | |
WORKDIR /var/www | |
RUN chgrp -R 0 /var/www && \ | |
chmod -R g=u /var/www && \ | |
rm -rf /tmp/app | |
RUN chown -R nginx. /var/www | |
COPY docker-entrypoint.sh / | |
RUN chmod +x /docker-entrypoint.sh | |
EXPOSE 80 | |
ENTRYPOINT /docker-entrypoint.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ docker build -t image_name .