首先创建php目录
mkdir /opt/dockerfile/php
cd /opt/dockerfile/php
编写dockerfile文件
vim Dockerfile
# 基础镜像
FROM centos:7.6.1810
# 镜像维护人
MAINTAINER zhengshaoyongzsy@163.com
RUN echo -e '/usr/local/lib64\n/usr/local/lib\n/usr/lib\n/usr/lib64'>> /etc/ld.so.conf \
&& ldconfig -v
#&& cat /etc/ld.so.conf
# 更换yum源
RUN yum -y install wget
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& yum makecache
# 安装依赖
RUN yum -y install epel-release libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-devel libmcrypt-devel wget
RUN yum -y install gcc gcc-c++ perl
#RUN wget https://nih.at/libzip/libzip-1.2.0.tar.gz
ADD libzip-1.2.0.tar.gz /usr/src/
WORKDIR /usr/src
RUN cd libzip-1.2.0 \
&& ./configure \
&& make -j8 \
&& make install
RUN cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
RUN echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf \
&& ldconfig -v
# 安装php
RUN wget https://www.php.net/distributions/php-7.3.8.tar.gz \
&& tar xvf php-7.3.8.tar.gz \
&& cd php-7.3.8 \
&& ./configure --prefix=/opt/php --exec-prefix=/opt/php \
--with-config-file-path=/opt/php/etc --enable-bcmath --enable-mbstring \
--with-gettext --enable-fpm --enable-shmop --enable-soap --enable-opcache \
--with-curl --disable-debug --disable-rpath \
--enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \
--with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli \
--with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar --with-libdir=lib64 --with-openssl \
&& make -j4 && make install
# 添加配置文件
WORKDIR /usr/src/php-7.3.8
RUN cp php.ini-development /opt/php/etc/php.ini
RUN cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
RUN cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf
# 修改配置文件为前台运行和允许所有IP访问
RUN sed -i 's/;daemonize = yes/daemonize = no/g' /opt/php/etc/php-fpm.conf \
&& sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' /opt/php/etc/php-fpm.d/www.conf
RUN cat /opt/php/etc/php-fpm.conf |grep daemonize
# 允许在命令行下使用php命令
RUN cp /opt/php/bin/php /usr/local/bin/php
WORKDIR /opt/php/
# 设置对外端口
EXPOSE 9000
# 启动php
CMD ["/opt/php/sbin/php-fpm"]
转载请注明:XAMPP中文组官网 » dockerfile编写自定义php镜像