Files
shop-platform/docker/php/Dockerfile

126 lines
3.7 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 使用官方PHP镜像
FROM php:7.4.33-fpm
# 设置工作目录
WORKDIR /var/www/html
# 拷贝本地的 sources.list 文件以加速 apt-get
COPY ./sources.list /etc/apt/sources.list
# 复制Supervisor配置
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 安装系统依赖
RUN apt-get update && apt-get install -y \
supervisor \
git \
curl \
vim \
libpng-dev \
libonig-dev \
libxml2-dev \
libssl-dev \
zip \
unzip \
libzip-dev \
default-mysql-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
iputils-ping \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 安装 WebSocat 完成后,清理缓存
COPY ./websocat /usr/local/bin/websocat
RUN chmod +x /usr/local/bin/websocat
# 安装 PHP 扩展
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
pdo_mysql \
mysqli \
mbstring \
exif \
pcntl \
bcmath \
gd \
zip \
sockets
# 安装 Redis 扩展
RUN pecl install redis-5.3.7 && docker-php-ext-enable redis
# 安装Composer
COPY --from=composer:2.2.25 /usr/bin/composer /usr/bin/composer
# 验证安装
RUN composer --version
# 修改 PHP 配置
RUN echo "memory_limit=256M" > /usr/local/etc/php/conf.d/memory-limit.ini \
&& echo "upload_max_filesize=150M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size=150M" >> /usr/local/etc/php/conf.d/uploads.ini
# # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作)
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html
# 暴露端口9000 为 PHP-FPM 端口8080 为 WebSocket 端口
EXPOSE 9000 8080
############ 查看 cron 进程
## 查看 cron 进程
# ps aux | grep "think cron:schedule"
# # 精确查找
# pgrep -f "think cron:schedule"
# # 查看进程树
# pstree -p | grep -i cron
## 启动 cron 任务
# 守护进程模式
# nohup php think cron:schedule > /dev/null 2>&1 &
#######################################
# 启动Supervisor
# 添加在Dockerfile末尾CMD命令之前
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
# 设置环境变量来控制entrypoint行为
# 可以通过docker run -e 或docker-compose.yml覆盖这些值
# ENV PHP_APP_ROOT=/var/www/html \
# USER_ID=33 \
# GROUP_ID=33
# ========================================
# Dockerfile 配置选项说明
# ========================================
#
# 1. 默认行为(当前配置):
# - 使用 /var/www/html 作为应用根目录
# - 启动 supervisord
# - 适用于标准Web应用
#
# 2. 自定义应用根目录:
# 在docker run时覆盖环境变量
# docker run -e PHP_APP_ROOT=/custom/app php-app
#
# 3. 传递路径参数给entrypoint
# 修改ENTRYPOINT来包含路径
# ENTRYPOINT ["/usr/local/bin/entrypoint.sh", "/custom/path"]
# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
#
# 4. 不同启动命令:
# 修改CMD来启动不同服务
# CMD ["php-fpm"] # 直接启动PHP-FPM
# CMD ["/bin/bash"] # 启动shell进行调试
# CMD ["apache2ctl", "-D", "FOREGROUND"] # 启动Apache
#
# ========================================
# 设置ENTRYPOINT注意这里不会带路径参数
# 路径可以通过环境变量PHP_APP_ROOT控制默认是/var/www/html
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# CMD会作为参数传递给entrypoint.sh
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]