forked from tangramor/nginx-php8-fpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.withoutNodejs
220 lines (204 loc) · 10.8 KB
/
Dockerfile.withoutNodejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
FROM php:8.3.11-fpm-alpine3.20
LABEL org.opencontainers.image.authors="Wang Junhua([email protected])"
LABEL org.opencontainers.image.url="https://www.github.com/tangramor/nginx-php8-fpm"
# China alpine mirror: mirrors.ustc.edu.cn
ARG APKMIRROR=dl-cdn.alpinelinux.org
USER root
WORKDIR /var/www/html
ENV TZ=Asia/Shanghai
# China php composer mirror: https://mirrors.cloud.tencent.com/composer/
ENV COMPOSERMIRROR="https://mirrors.cloud.tencent.com/composer/"
COPY conf/supervisord.conf /etc/supervisord.conf
COPY conf/php-fpm.conf /etc/supervisor/conf.d/php-fpm.conf
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/default.conf /etc/nginx/conf.d/default.conf
# COPY conf/resolv.conf /etc/resolv.conf
COPY start.withoutNodejs.sh /start.sh
ENV PHP_MODULE_DEPS gcc make libc-dev rabbitmq-c-dev zlib-dev libmemcached-dev cyrus-sasl-dev libpng-dev libxml2-dev krb5-dev curl-dev icu-dev libzip-dev openldap-dev imap-dev postgresql-dev libjpeg-turbo-dev freetype-dev libwebp-dev gettext-dev imagemagick-dev
# ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
# ENV MUSL_LOCPATH /usr/share/i18n/locales/musl
ENV NGINX_VERSION 1.27.1
ENV NGINX_PKG_RELEASE 1
ENV NJS_VERSION 0.8.5
ENV PKG_RELEASE 2
RUN if [ "$APKMIRROR" != "dl-cdn.alpinelinux.org" ]; then sed -i 's/dl-cdn.alpinelinux.org/'$APKMIRROR'/g' /etc/apk/repositories; fi \
&& set -x \
&& apk update \
# add utf-8 locale support
# && apk add --no-cache $MUSL_LOCALE_DEPS \
# && wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip \
# && unzip musl-locales-master.zip \
# && cd musl-locales-master \
# && cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install \
# && cd .. && rm -rf musl-locales-master* \
# add locale support by glibc
# && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
# && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-2.35-r0.apk \
# && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-bin-2.35-r0.apk \
# && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-i18n-2.35-r0.apk \
# && apk add --allow-untrusted glibc-2.35-r0.apk glibc-bin-2.35-r0.apk glibc-i18n-2.35-r0.apk \
# && /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 \
# && rm -f *.apk \
# && echo "export PATH=/usr/glibc-compat/bin:$PATH" >> ~/.bashrc \
# set default locale
# && echo "export LANG=en_US.UTF-8" >> ~/.bashrc \
# && echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc \
# create nginx user/group first, to be consistent throughout docker variants
&& addgroup -g 101 -S nginx \
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
&& apkArch="$(cat /etc/apk/arch)" \
&& nginxPackages=" \
nginx=${NGINX_VERSION}-r${NGINX_PKG_RELEASE} \
nginx-module-xslt=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-geoip=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-image-filter=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-r${NGINX_PKG_RELEASE} \
" \
&& case "$apkArch" in \
x86_64|aarch64) \
# arches officially built by upstream
set -x \
&& KEY_SHA512="de7031fdac1354096d3388d6f711a508328ce66c168967ee0658c294226d6e7a161ce7f2628d577d56f8b63ff6892cc576af6f7ef2a6aa2e17c62ff7b6bf0d98 *stdin" \
&& apk add --no-cache --virtual .cert-deps \
openssl \
&& wget -O /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub \
&& if [ "$(openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout | openssl sha512 -r)" = "$KEY_SHA512" ]; then \
echo "key verification succeeded!"; \
mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/; \
else \
echo "key verification failed!"; \
exit 1; \
fi \
&& apk del .cert-deps \
&& apk add -X "https://nginx.org/packages/mainline/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from the published packaging sources
set -x \
&& tempDir="$(mktemp -d)" \
&& chown nobody:nobody $tempDir \
&& apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils \
&& su nobody -s /bin/sh -c " \
export HOME=${tempDir} \
&& cd ${tempDir} \
&& hg clone https://hg.nginx.org/pkg-oss \
&& cd pkg-oss \
&& hg up ${NGINX_VERSION}-${PKG_RELEASE} \
&& cd alpine \
&& make all \
&& apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz \
" \
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
&& apk del .build-deps \
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
;; \
esac \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
&& if [ -n "/etc/apk/keys/abuild-key.rsa.pub" ]; then rm -f /etc/apk/keys/abuild-key.rsa.pub; fi \
&& if [ -n "/etc/apk/keys/nginx_signing.rsa.pub" ]; then rm -f /etc/apk/keys/nginx_signing.rsa.pub; fi \
# Bring in gettext so we can get `envsubst`, then throw
# the rest away. To do this, we need to install `gettext`
# then move `envsubst` out of the way so `gettext` can
# be deleted completely, then move `envsubst` back.
&& apk add --no-cache --virtual .gettext gettext \
&& mv /usr/bin/envsubst /tmp/ \
\
&& runDeps="$( \
scanelf --needed --nobanner /tmp/envsubst \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache $runDeps \
&& apk del .gettext \
&& mv /tmp/envsubst /usr/local/bin/ \
# Bring in tzdata so users could set the timezones through the environment
# variables
&& apk add --no-cache tzdata \
# Bring in curl and ca-certificates to make registering on DNS SD easier
&& apk add --no-cache curl ca-certificates \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
ENV fpm_conf /usr/local/etc/php-fpm.d/www.conf
ENV php_vars /usr/local/etc/php/conf.d/docker-vars.ini
RUN echo "cgi.fix_pathinfo=0" > ${php_vars} &&\
echo "upload_max_filesize = 100M" >> ${php_vars} &&\
echo "post_max_size = 100M" >> ${php_vars} &&\
echo "variables_order = \"EGPCS\"" >> ${php_vars} && \
echo "memory_limit = 128M" >> ${php_vars} && \
sed -i \
-e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" \
-e "s/pm.max_children = 5/pm.max_children = 64/g" \
-e "s/pm.start_servers = 2/pm.start_servers = 8/g" \
-e "s/pm.min_spare_servers = 1/pm.min_spare_servers = 8/g" \
-e "s/pm.max_spare_servers = 3/pm.max_spare_servers = 32/g" \
-e "s/;pm.max_requests = 500/pm.max_requests = 800/g" \
-e "s/user = www-data/user = nginx/g" \
-e "s/group = www-data/group = nginx/g" \
-e "s/;listen.mode = 0660/listen.mode = 0666/g" \
-e "s/;listen.owner = www-data/listen.owner = nginx/g" \
-e "s/;listen.group = www-data/listen.group = nginx/g" \
-e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" \
-e "s/^;clear_env = no$/clear_env = no/" \
${fpm_conf} \
&& cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
# && sed -i 's/session.save_handler = files/session.save_handler = redis\nsession.save_path = "tcp:\/\/redis:6379"/g' /usr/local/etc/php/php.ini
RUN curl http://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& apk add --no-cache libstdc++ mysql-client bash bash-completion shadow linux-headers \
supervisor git zip unzip coreutils libpng libmemcached-libs krb5-libs icu-libs \
icu c-client libzip openldap-clients imap postgresql-client postgresql-libs libcap tzdata sqlite \
lua-resty-core nginx-mod-http-lua rabbitmq-c gettext imagemagick \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& set -xe \
&& apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \
&& apk add --no-cache --update --virtual .all-deps $PHP_MODULE_DEPS \
&& docker-php-ext-configure gd --with-jpeg --with-freetype --with-webp \
&& docker-php-ext-install exif sockets gd bcmath intl soap mysqli pdo pdo_mysql pgsql pdo_pgsql zip ldap imap dom opcache gettext \
&& printf "\n\n" | pecl install amqp \
&& docker-php-ext-enable amqp \
&& printf "\n\n\n\n" | pecl install -o -f redis \
&& docker-php-ext-enable redis \
&& docker-php-ext-enable sockets \
&& pecl install msgpack && docker-php-ext-enable msgpack \
&& pecl install igbinary && docker-php-ext-enable igbinary \
&& pecl install swoole && docker-php-ext-enable swoole \
&& printf "\n\n\n\n\n\n\n\n\n\n" | pecl install memcached \
&& docker-php-ext-enable memcached \
&& pecl install mongodb \
&& docker-php-ext-enable mongodb \
&& printf "\n" | pecl install imagick \
&& docker-php-ext-enable imagick \
&& rm -rf /tmp/pear \
&& apk del .all-deps .phpize-deps \
# && composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/ \
# && if [ "$COMPOSERMIRROR" != "" ]; then composer config -g repos.packagist composer ${COMPOSERMIRROR}; fi \
&& rm -rf /var/cache/apk/* /tmp/* /var/tmp/* \
&& rm -f /etc/nginx/conf.d/default.conf.apk-new && rm -f /etc/nginx/nginx.conf.apk-new \
&& if [ "$APKMIRROR" != "dl-cdn.alpinelinux.org" ]; then sed -i 's/'$APKMIRROR'/dl-cdn.alpinelinux.org/g' /etc/apk/repositories; fi \
&& set -ex \
&& setcap 'cap_net_bind_service=+ep' /usr/local/bin/php \
&& mkdir -p /var/log/supervisor \
&& chmod +x /start.sh
EXPOSE 443 80
CMD ["/start.sh"]