42 lines
1.2 KiB
Docker
42 lines
1.2 KiB
Docker
FROM php:8.1-apache
|
|
|
|
# 安装 PHP 扩展
|
|
RUN apt-get update && apt-get install -y \
|
|
libzip-dev \
|
|
libpng-dev \
|
|
libcurl4-openssl-dev \
|
|
&& docker-php-ext-install pdo pdo_mysql mysqli zip gd curl \
|
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
# 启用 Apache mod_rewrite
|
|
RUN a2enmod rewrite
|
|
|
|
# 设置 Apache DocumentRoot
|
|
ENV APACHE_DOCUMENT_ROOT /var/www/html
|
|
|
|
RUN sed -i 's|/var/www/html|${APACHE_DOCUMENT_ROOT}|g' \
|
|
/etc/apache2/sites-available/000-default.conf \
|
|
/etc/apache2/apache2.conf
|
|
|
|
# 允许 .htaccess 覆盖
|
|
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
|
|
|
# 设置时区
|
|
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
|
|
|
# 拷贝应用代码
|
|
COPY api/ /var/www/html/
|
|
COPY env_config.php /var/www/env_config.php
|
|
# .env 由 docker-compose env_file 注入,不打包进镜像
|
|
|
|
# 设置权限
|
|
RUN chown -R www-data:www-data /var/www/html
|
|
|
|
# 拷贝并设置启动入口脚本(用于替换 JS 中的硬编码域名)
|
|
COPY docker/api/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
EXPOSE 80
|
|
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|