Dockerfile构建php镜像

简单介绍一下Dockerfile:

FROM centos:7 表示依赖centos:7版本的镜像,如果没有对应的镜像,会自动拉去最新的cenos:7镜像

RUN yum -y install libxml2 表示执行某一条命令

ENV 表示构建镜像过程中的环境变量,执行的时候可用

ENTRYPOINT 表示类似CMD命令,执行某条指令,比如执行nginx:ENTRYPOINT  [ "nginx", "-g", "daemon off;" ]

好了解释完了基本命令,现在来构建一个php环境的镜像。

创建Dockerfile文件,输入以下内容:

FROM centos:7 

ENV PHP_INI_DIR /usr/local/php/etc

RUN yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel

RUN yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-6.8.2-1.el7.x86_64.rpm
RUN yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-6.8.2-1.el7.x86_64.rpm

RUN cd /tmp
RUN wget wget https://www.php.net/distributions/php-7.4.7.tar.xz && xz -d php-7.4.7.tar.xz && tar -xvf php-7.4.7.tar

RUN ./configure \
    --with-config-file-path="$PHP_INI_DIR" \
    --with-pear --enable-bcmath --with-curl --enable-gd --with-libdir=lib64 --with-bz2 --with-zlib --enable-soap --enable-sockets --with-mysqli --with-pdo-mysql  --with-curl --enable-fpm --enable-mbstring --enable-sockets --enable-gd --with-openssl


RUN make && make install

RUN cp /tmp/php-7.4.7/php.ini-production /usr/local/php/etc/php.ini
# 如有需要可以打开
# RUN cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# RUN cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

RUN sed -i "s/memory_limit = 128M/memory_limit = 1024M/g" /usr/local/php/etc/php.ini 

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r
"unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
composer config -g repo.packagist composer https:
//mirrors.aliyun.com/composer

RUN pecl channel-update pecl.php.net

RUN pecl install -o -f redis && \ echo extension=redis.so >> /usr/local/php/etc/php.ini
ENTRYPOINT [] 

WORKDIR /workdir

 

进入Dockerfile目录,执行docker build . 

等待镜像构建,至此,php环境的镜像就完成了

你可能感兴趣的:(Dockerfile构建php镜像)