引用官方的 php:7.3-fpm 镜像

默认debian系统,网络不畅可以替换sources.list

sources.list

1
2
3
4
5
6
7
8
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

opcache.ini

1
2
3
4
5
6
7
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

www.conf

1
2
3
4
5
6
7
8
9
[www]
user = www-data
group = www-data
listen = 9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
FROM php:7.3-fpm
COPY sources.list /etc/apt/sources.list
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY opcache.ini $PHP_INI_DIR/conf.d/
COPY www.conf /usr/local/etc/php-fpm.d/
RUN apt update && apt -y install procps net-tools pkg-config libpcre3-dev libpng-dev libjpeg62-turbo-dev libfreetype6-dev postgresql-server-dev-all libzip-dev
RUN docker-php-ext-install -j$(nproc) opcache \
&& docker-php-ext-install -j$(nproc) gettext \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install -j$(nproc) mysqli \
&& docker-php-ext-install -j$(nproc) pdo_mysql \
&& docker-php-ext-install -j$(nproc) pdo_pgsql \
&& docker-php-ext-install -j$(nproc) pgsql \
&& docker-php-ext-install -j$(nproc) zip \
&& pecl install https://pecl.php.net/get/mongodb-1.6.0.tgz \
&& pecl install https://pecl.php.net/get/redis-5.1.1.tgz \
&& docker-php-ext-enable redis mongodb
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN rm -rf /var/lib/apt/lists/*

部分配置解释

  • 主要部分为扩展自定义安装,借用官方的 docker-php-ext-install 安装核心扩展
  • postgresql-server-dev-all,libzip-dev 为pgsql和zip所需的开发包
  • docker-php-ext-configure –with 命令当此扩展需要指定配置参数时候,才使用
  • www.conf 配置仅修改 listen 为 9000
  • 由于安装的扩展比较多 总大小为 900m,可参考进行自定义