Files
shop-platform/docker/php/Dockerfile

98 lines
2.6 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 \
&& rm -rf /var/lib/apt/lists/*
# 安装 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
# 安装 Xdebug兼容 PHP 7.4 的版本)
RUN pecl install xdebug-3.1.6 && docker-php-ext-enable xdebug
# 安装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=50M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size=50M" >> /usr/local/etc/php/conf.d/uploads.ini
# 创建 Xdebug 配置
RUN echo "zend_extension=xdebug.so" > /usr/local/etc/php/conf.d/xdebug.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
# # 创建非 root 用户
# RUN useradd -m -u 1000 phpuser && chown -R phpuser:phpuser /var/www/html
# USER phpuser
# 暴露端口
EXPOSE 9000 9003
############ 查看 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 ["/usr/local/bin/entrypoint.sh"]
# 修改CMD命令
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]