Dockerfile制作php镜像
Dockerfile内容
FROM ubuntu:20.04 ADD composer-v2.1 /usr/local/sbin/
ADD pcre2-10.39.tar.gz /tmp
ADD libzip-1.8.0.tar.gz /tmp
ADD php-7.4.24.tar.gz /tmp
ADD sources.list /etc/apt/wget https://pecl.php.net/get/psr-1.2.0.tgz
COPY memcached-3.1.5.tgz /tmp
COPY mcrypt-1.0.4.tgz /tmp
COPY phalcon-4.1.2.tgz /tmp
COPY psr-1.2.0.tgz /tmp
COPY redis-5.3.7.tgz /tmp
COPY imagick-3.7.0.tgz /tmp
COPY igbinary-3.2.7.tgz /tmpENV PKG_CONFIG_PATH /usr/local/pcre2-10.39/lib/pkgconfig:${PKG_CONFIG_PATH}
ENV PATH /usr/local/php/bin:$PATHENV BUILD_DEPS_REMOVED cmake pkg-config make autoconf file
ENV BUILD_DEPS libmemcached-dev zlib1g-dev libargon2-dev libreadline-dev libgmp-dev libssl-dev libsqlite3-dev libbz2-dev libcurl4-openssl-dev libgdbm-dev libsodium-dev libldap2-dev libonig-dev libmcrypt-dev libpcre2-dev libxslt1-dev libxml2-dev unzip libmagickwand-dev libpng-dev libjpeg-dev libfreetype-dev gcc
RUN apt-get update && apt-get install -y tzdata &&
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&
dpkg-reconfigure -f noninteractive tzdata &&
apt-get -y install --no-install-recommends ${BUILD_DEPS_REMOVED} ${BUILD_DEPS} &&
chmod +x /usr/local/sbin/composer-v2.1 &&
cd /tmp/pcre2-10.39 &&
./configure --prefix=/usr/local/pcre2-10.39 --enable-pcre2-16 --enable-pcre2-32 --enable-jit --enable-jit-sealloc &&
make -j 8 && make install &&
cd /tmp/libzip-1.8.0 &&
mkdir build && cd build &&
cmake .. && make -j 8 && make install &&
ln -sv /usr/local/lib/libzip.so.5 /usr/lib/ &&
cd /tmp/php-7.4.24 &&
./configure --prefix=/usr/local/php-7.4.24 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-config-file-path=/usr/local/php-7.4.24/conf --disable-rpath --enable-option-checking=fatal --with-pic --enable-ftp --enable-soap --with-xmlrpc --with-openssl --with-mhash --with-external-pcre --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-openssl-dir --with-jpeg --with-zlib-dir --with-freetype --with-gettext --with-gmp --enable-mbstring --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-sockets --enable-sysvmsg --with-xsl --with-zip --with-pear --enable-opcache --enable-session --enable-xml --with-webp --with-xpm --with-gdbm --with-ldap=shared --with-sodium=shared --with-password-argon2 --with-libxml &&
make -j 8 && make install &&
ln -sv /usr/local/php-7.4.24 /usr/local/php &&
mkdir -pv /usr/local/php/conf &&
cp /tmp/php-7.4.24/php.ini-production /usr/local/php/conf/php.ini &&
chmod 644 /usr/local/php/conf/php.ini &&
pecl channel-update pecl.php.net &&
pecl install /tmp/memcached-3.1.5.tgz &&
pecl install /tmp/mcrypt-1.0.4.tgz &&
pecl install /tmp/redis-5.3.7.tgz &&
pecl install /tmp/psr-1.2.0.tgz &&
pecl install /tmp/phalcon-4.1.2.tgz &&
pecl install /tmp/imagick-3.7.0.tgz &&
pecl install /tmp/igbinary-3.2.7.tgz &&
echo "extension=memcached.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=mcrypt.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=redis.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=phalcon.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=psr.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=imagick.so" >> /usr/local/php-7.4.24/conf/php.ini &&
echo "extension=igbinary.so" >> /usr/local/php-7.4.24/conf/php.ini &&
cd /tmp/php-7.4.24/ext/gd/ &&
/usr/local/php-7.4.24/bin/phpize &&
./configure --with-php-config=/usr/local/php-7.4.24/bin/php-config --with-freetype --with-jpeg --enable-gd --enable-gd-jis-conv &&
make -j 8 && make install &&
echo "extension=gd.so" >> /usr/local/php-7.4.24/conf/php.ini &&
#apt-get purge -y --auto-remove ${BUILD_DEPS_REMOVED} &&
rm -rf /tmp/* &&
apt-get autoclean && apt-get clean
制作镜像
cat build_image.sh #!/bin/bash
docker build -t 172.16.1.20/xk-base/php-7.4.24:v0.2 .
查看镜像信息
~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.16.1.20/xk-base/php-7.4.24 v0.2 3b75411dae84 2 minutes ago 1.03GB