# 使用一个包含基本编译工具的基础镜像
FROM ubuntu:latest
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 更新包列表并安装必要的编译工具和库
RUN apt-get update && apt-get install -y \
vim \
wget \
gnupg \
dirmngr \
build-essential \
zlib1g-dev \
libbz2-dev \
libcurl4-openssl-dev \
libreadline-dev \
libonig-dev \
libxml2-dev \
libpng-dev \
libfreetype6-dev \
libssl-dev \
libjpeg-dev \
libmcrypt-dev \
libmhash-dev \
libxpm-dev \
libx11-dev \
libxext-dev \
libxi-dev \
libxrender-dev \
libxt-dev \
libxpm-dev \
libfontconfig1-dev \
&& rm -rf /var/lib/apt/lists/*
# 设置PHP源代码的下载URL和版本
ENV PHP_VERSION=7.4.33
ENV PHP_SOURCE_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz"
# 下载PHP源代码
WORKDIR /tmp
RUN wget -O php.tar.gz "${PHP_SOURCE_URL}"
# 解压源代码
RUN tar -xf php.tar.gz
# 进入PHP源代码目录
WORKDIR /tmp/php-${PHP_VERSION}
# 配置PHP安装选项(这里只是一个示例,你可能需要调整)
RUN ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--without-sqlite3 \
--without-pdo_sqlite \
--enable-mbstring \
--enable-zip \
--enable-bcmath \
--enable-sockets \
--enable-fpm \
--enable-opcache \
--enable-intl \
--enable-pcntl \
--enable-ftp \
--enable-php.ini \
--with-openssl \
--enable-mysqlnd-compression-support \
--with-pear \
&& make -j$(nproc) \
&& make install
# 设置PHP配置文件(如果需要)
# COPY php.ini /usr/local/php/etc/
RUN mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
RUN mv /tmp/php-7.4.33/php.ini-production /usr/local/php/etc/php.ini
RUN mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
RUN sed -i 's/listen \= 127.0.0.1:9000/listen \= 0.0.0.0:8999/g' /usr/local/php/etc/php-fpm.d/www.conf
RUN sed -i 's/pm.max_children \= 5/pm.max_children \= 20/g' /usr/local/php/etc/php-fpm.d/www.conf
RUN groupadd nobody
# 设置工作目录
WORKDIR /app/html
# 暴露端口(如果需要运行Web服务器)
# 设置容器启动时运行的命令(如果需要)
#CMD ["/usr/local/php/sbin/php-fpm","-D"]
CMD ["/usr/local/php/sbin/php-fpm","-F"]
EXPOSE 8999
启动方式:
docker run -d --name cc-php -p 8999:8999 -v /app/html:/app/html cc-php:7.4.33-fpm