Last active
March 29, 2019 08:29
-
-
Save heyanlong/7add8f3b4b841b5c3243da6ccdf670b3 to your computer and use it in GitHub Desktop.
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
FROM debian:stretch-slim | |
ENV NGINX_VERSION 1.14.2 | |
ENV PHP_VERSION 7.2.16 | |
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2" | |
ENV PHP_CPPFLAGS="$PHP_CFLAGS" | |
ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie" | |
RUN set -eux; \ | |
\ | |
{ \ | |
echo 'Package: php*'; \ | |
echo 'Pin: release *'; \ | |
echo 'Pin-Priority: -1'; \ | |
} > /etc/apt/preferences.d/no-debian-php; \ | |
sed -i "s@http://deb.debian.org@http://mirrors.163.com@g" /etc/apt/sources.list; \ | |
apt-get update; apt-get install -y \ | |
supervisor \ | |
procps \ | |
ca-certificates \ | |
curl \ | |
xz-utils \ | |
--no-install-recommends; rm -r /var/lib/apt/lists/*; \ | |
# download | |
curl http://cn2.php.net/distributions/php-${PHP_VERSION}.tar.gz -o /tmp/php-${PHP_VERSION}.tar.gz; \ | |
curl https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -o /tmp/nginx-${NGINX_VERSION}.tar.gz; \ | |
curl https://pecl.php.net/get/uuid-1.0.4.tgz -o /tmp/uuid-1.0.4.tgz; \ | |
curl https://pecl.php.net/get/yaf-3.0.8.tgz -o /tmp/yaf-3.0.8.tgz; \ | |
curl https://pecl.php.net/get/amqp-1.9.4.tgz -o /tmp/amqp-1.9.4.tgz; \ | |
curl https://pecl.php.net/get/zookeeper-0.6.4.tgz -o /tmp/zookeeper-0.6.4.tgz; \ | |
curl https://pecl.php.net/get/mongodb-1.3.4.tgz -o /tmp/mongodb-1.3.4.tgz; \ | |
curl https://pecl.php.net/get/redis-4.3.0.tgz -o /tmp/redis-4.3.0.tgz; \ | |
# 编译依赖 | |
savedAptMark="$(apt-mark showmanual)"; \ | |
apt-get update; \ | |
apt-get install -y --no-install-recommends \ | |
autoconf \ | |
dpkg-dev \ | |
file \ | |
g++ \ | |
gcc \ | |
libc-dev \ | |
make \ | |
pkg-config \ | |
re2c \ | |
uuid-dev \ | |
librabbitmq-dev \ | |
libcurl4-openssl-dev \ | |
libedit-dev \ | |
libsodium-dev \ | |
libsqlite3-dev \ | |
libssl-dev \ | |
libjpeg62-turbo-dev \ | |
libpng-dev \ | |
libfreetype6-dev \ | |
libpcre3-dev \ | |
libxml2-dev \ | |
zlib1g-dev \ | |
libzookeeper-mt-dev \ | |
; \ | |
##<argon2>## | |
sed -e 's/stretch/buster/g' /etc/apt/sources.list > /etc/apt/sources.list.d/buster.list; \ | |
{ \ | |
echo 'Package: *'; \ | |
echo 'Pin: release n=buster'; \ | |
echo 'Pin-Priority: -10'; \ | |
echo; \ | |
echo 'Package: libargon2*'; \ | |
echo 'Pin: release n=buster'; \ | |
echo 'Pin-Priority: 990'; \ | |
} > /etc/apt/preferences.d/argon2-buster; \ | |
apt-get update; \ | |
apt-get install -y --no-install-recommends libargon2-dev; \ | |
##</argon2>## | |
rm -rf /var/lib/apt/lists/*; \ | |
cd /tmp; \ | |
# nginx | |
tar -zxf nginx-${NGINX_VERSION}.tar.gz; \ | |
cd nginx-${NGINX_VERSION}; \ | |
./configure --prefix=/usr/local/nginx; \ | |
make -j "$(nproc)"; \ | |
find -type f -name '*.a' -delete; \ | |
make install; \ | |
find /usr/local/nginx/sbin -type f -executable -exec strip --strip-all '{}' + || true; \ | |
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ ; \ | |
make clean; \ | |
# PHP | |
cd /tmp; \ | |
export \ | |
CFLAGS="$PHP_CFLAGS" \ | |
CPPFLAGS="$PHP_CPPFLAGS" \ | |
LDFLAGS="$PHP_LDFLAGS" \ | |
; \ | |
tar -zxf php-${PHP_VERSION}.tar.gz; \ | |
cd php-${PHP_VERSION}; \ | |
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ | |
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \ | |
if [ ! -d /usr/include/curl ]; then \ | |
ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \ | |
fi; \ | |
./configure \ | |
--prefix=/usr/local/php \ | |
--build="$gnuArch" \ | |
--enable-option-checking=fatal \ | |
--enable-fpm \ | |
--enable-bcmath \ | |
--enable-calendar \ | |
--enable-exif \ | |
--enable-ftp \ | |
--enable-intl \ | |
--enable-mbstring \ | |
--enable-sockets \ | |
--enable-zip \ | |
--enable-mysqlnd \ | |
--with-gd \ | |
#--with-webp-dir \ | |
--with-jpeg-dir \ | |
--with-png-dir \ | |
--with-freetype-dir \ | |
--with-gettext \ | |
--with-mhash \ | |
--with-pdo-mysql \ | |
--with-password-argon2 \ | |
--with-sodium \ | |
--with-curl \ | |
--with-openssl \ | |
--with-zlib \ | |
--with-pear \ | |
--with-libdir="lib/$debMultiarch" \ | |
; \ | |
make -j "$(nproc)"; \ | |
find -type f -name '*.a' -delete; \ | |
make install; \ | |
find /usr/local/php/bin /usr/local/php/sbin -type f -executable -exec strip --strip-all '{}' + || true; \ | |
ln -s /usr/local/php/sbin/* /usr/sbin/ ; \ | |
ln -s /usr/local/php/bin/* /usr/bin/ ; \ | |
make clean; \ | |
# 安装extension | |
cd /tmp; \ | |
tar xf uuid-1.0.4.tgz; \ | |
tar xf yaf-3.0.8.tgz; \ | |
tar xf amqp-1.9.4.tgz; \ | |
tar xf zookeeper-0.6.4.tgz; \ | |
tar xf mongodb-1.3.4.tgz; \ | |
tar xf redis-4.3.0.tgz; \ | |
# uuid | |
cd uuid-1.0.4; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
cd yaf-3.0.8; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
cd amqp-1.9.4; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
cd zookeeper-0.6.4; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
cd mongodb-1.3.4; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
cd redis-4.3.0; phpize; ./configure; make -j "$(nproc)"; make install; cd /tmp; \ | |
# 删除依赖 | |
apt-mark auto '.*' > /dev/null; \ | |
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ | |
find /usr/local -type f -executable -exec ldd '{}' ';' \ | |
| awk '/=>/ { print $(NF-1) }' \ | |
| sort -u \ | |
| xargs -r dpkg-query --search \ | |
| cut -d: -f1 \ | |
| sort -u \ | |
| xargs -r apt-mark manual \ | |
; \ | |
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | |
rm -fr /tmp/*; \ | |
mkdir -p /usr/local/php/logs; \ | |
mkdir -p /opt/app/public; \ | |
echo "<?php echo 'hello php';" > /opt/app/public/index.php | |
ADD container-files / | |
ENTRYPOINT ["/config/bootstrap.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment