Files
youlegames/codes/agent/game-docker/docker/dlweb/Dockerfile
2026-04-13 17:06:02 +08:00

51 lines
1.9 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.
FROM php:8.1-apache
# 切换为阿里云 Debian 镜像源(加速国内构建)
RUN sed -i 's|http://deb.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
sed -i 's|http://deb.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list
# 安装 PHP 扩展(包含 Redis
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 \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 启用 Apache mod_rewrite
RUN a2enmod rewrite
# 设置 Apache DocumentRoot 到 dlweb/api
ENV APACHE_DOCUMENT_ROOT /var/www/html/api
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
# 关闭 PHP 错误输出到响应体,开启输出缓冲(与 Windows 行为一致)
RUN echo 'display_errors = Off\nerror_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT\noutput_buffering = 4096\nlog_errors = On\nerror_log = /var/log/apache2/php_errors.log' > /usr/local/etc/php/conf.d/production.ini
# 拷贝应用代码
COPY dlweb/ /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/HTML 中的硬编码域名)
COPY docker/dlweb/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
EXPOSE 80
ENTRYPOINT ["docker-entrypoint.sh"]