创建镜像构建目录
mkdir -p /opt/docker/php
cd /opt/docker/php
下载php软件包
wget http://cn2.php.net/distributions/php-7.2.33.tar.gz -P /opt/docker/php
编写Dockerfile文件install
FROM centos
MAINTAINER swift
#RUN dnf install -y glibc-langpack-en && \
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \
dnf install -y dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
#dnf -y module list php && \
#dnf -y module enable php:remi-7.3 && \
RUN dnf install -y epel-release
RUN dnf -y install git wget lrzsz vim libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg-turbo libjpeg-turbo-devel libpng-devel libpng freetype-devel freetype icu libicu-devel libicu libmcrypt libmcrypt-devel libxslt libxslt-devel php-mysqlnd gcc gcc-c++ glibc-headers make autoconf && \
dnf clean all
#dnf -y groupinstall "Development Tools" && \
RUN groupadd www
RUN useradd -g www www
ADD php-7.2.33.tar.gz /usr/local/src/
RUN cd /usr/local/src/php-7.2.33 && \
./configure --prefix=/usr/local/php72 \
--with-config-file-path=/usr/local/php72/etc \
--with-config-file-scan-dir=/usr/local/php72/conf.d \
--enable-fpm --with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--enable-intl \
--with-xsl && \
make -j 4 && make install && \
cp /usr/local/php72/etc/php-fpm.conf.default /usr/local/php72/etc/php-fpm.conf && \
cp ./php.ini-production /usr/local/php72/etc/php.ini && \
cp /usr/local/php72/etc/php-fpm.d/www.conf.default /usr/local/php72/etc/php-fpm.d/www.conf && \
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && \
chmod +x /etc/init.d/php-fpm && \
rm -rf /usr/loacl/src/php-7.2.33
EXPOSE 9000
ENTRYPOINT /etc/init.d/php-fpm start && tail -f /usr/local/php72/var/log/php-fpm.log
构建php镜像
docker build -t dockerfile/php7-2:v1 .
测试使用镜像
docker run -d -p 9000:9000 --name php-test dockerfile/php7-2:v1
#查看docker是否运行
docker ps | grep php-test
#查看端口
ss -anlptu | grep 9000
#查看日志
docker logs php-test -f
添加redis扩展
mkdir -p /opt/docker/php/php-redis
cd /opt/docker/php/php-redis
以dockerfile/php7-2:v1为基础进行扩展
FROM dockerfile/php7-2:v1
MAINTAINER swift
RUN cd /usr/local/src
RUN yum install -y autoconf
ADD phpredis-develop.tar.gz /usr/local/src/
RUN mv /usr/local/src/phpredis-develop /usr/local/src/phpredis72
RUN cd /usr/local/src/phpredis72 && \
/usr/local/php72/bin/phpize && \
./configure --with-php-config=/usr/local/php72/bin/php-config && \
make && make install && \
echo extension=redis.so >> /usr/local/php72/etc/php.ini
build镜像
docker build -t dockerfile/php7-2-redis:v1 .
创建测试容器验证
docker run -d -p 9006:9000 --name php-test-redis dockerfile/php7-2-redis:v1
查看redis模块是否加载
docker exec -it php-test-redis bash -c '/usr/local/php72/bin/php -m | grep redis'