基于Alpine Linux 制作的,docker 的 PHP-FPM 8.0 & Nginx 1.20容器
特点:1、基于轻量级和安全的 Alpine Linux 发行版多平台,支持 AMD4,ARMv6,ARMv7,ARM64
2、非常小的 Docker 图像大小(+/-40 MB)
3、 使用 PHP 8.0以获得更好的性能、更低的 CPU 使用率和内存占用,
4、为100个并发用户优化,优化为只在有流量时使用资源(通过使用 PHP-FPM 的按需流程管理器)
5、服务 Nginx、 PHP-FPM 和监督协议在非特权用户(无人)下运行,以使其更安全
6、所有服务的日志被重定向到 Docker 容器的输出(可以通过 Docker logs-f < container name > 看到)
7、遵循 KISS 原则(Keep It Simple, Stupid)) ,使其易于理解,并根据您的需要调整镜像
拉取镜像: docker pull trafex/php-nginx
用法: 启用 docker run -p 80:8080 trafex/php-nginx
查看 PHP 信息: http://localhost ,或静态 html 页面: http://localhost/test.html
加载自己的php代码:
docker run -p 80:8080 -v ~/my-codebase:/var/www/html trafex/php-nginx
配置 用法
在 config中你可以找到 Nginx、 PHP 和 PHP-fpm 的默认配置文件。如果要扩展或自定义,可以在正确的文件夹中挂载配置文件;
nginx配置
docker run -v "`pwd`/nginx-server.conf:/etc/nginx/conf.d/server.conf" trafex/php-nginx
php配置
docker run -v "`pwd`/php-setting.ini:/etc/php8/conf.d/settings.ini" trafex/php-nginx
PHP-FPM 配置
docker run -v "`pwd`/php-fpm-settings.conf:/etc/php8/php-fpm.d/server.conf" trafex/php-nginx
注意: 因为-v 需要一个绝对路径,我在例子中添加了 pwd 来返回到工作目录的绝对路径
添加composer
如果你的项目中需要使用 Composer,这里有一个简单的方法来添加它。
FROM trafex/php-nginx:latest
#从官方镜像中安装
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Run composer install to install the dependencies
RUN composer install --optimize-autoloader --no-interaction --no-progress
编译安装composer
FROM composer AS composer
# copying the source directory and install the dependencies with composer
COPY <your_directory>/ /app
# run composer install to install the dependencies
RUN composer install \
--optimize-autoloader \
--no-interaction \
--no-progress
# continue stage build with the desired image and copy the source including the
# dependencies downloaded by composer
FROM trafex/php-nginx
COPY --chown=nginx --from=composer /app /var/www/html