mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 13:32:41 +08:00
add docker
This commit is contained in:
71
.docker/php/Dockerfile
Normal file
71
.docker/php/Dockerfile
Normal file
@@ -0,0 +1,71 @@
|
||||
# 👷♀️ 第一阶段:构建阶段,包含所有开发依赖
|
||||
FROM php:8.2-fpm-alpine AS builder
|
||||
|
||||
RUN apk add --no-cache \
|
||||
$PHPIZE_DEPS \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
libjpeg-turbo-dev \
|
||||
freetype-dev \
|
||||
icu-dev \
|
||||
libxml2-dev \
|
||||
libwebp-dev \
|
||||
gmp-dev \
|
||||
oniguruma-dev \
|
||||
linux-headers
|
||||
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp
|
||||
|
||||
RUN docker-php-ext-install -j$(nproc) \
|
||||
bcmath \
|
||||
pdo_mysql \
|
||||
mysqli \
|
||||
gd \
|
||||
pcntl \
|
||||
sockets \
|
||||
gmp \
|
||||
zip \
|
||||
intl \
|
||||
opcache
|
||||
|
||||
# 安装 redis 扩展
|
||||
RUN pecl install redis && docker-php-ext-enable redis
|
||||
|
||||
# 👨🍳 第二阶段:运行阶段,仅包含必要运行环境
|
||||
FROM php:8.2-fpm-alpine
|
||||
|
||||
# 复制已构建的扩展
|
||||
COPY --from=builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions
|
||||
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
|
||||
|
||||
# 安装运行时所需依赖
|
||||
RUN apk add --no-cache \
|
||||
wget \
|
||||
rsync \
|
||||
libzip \
|
||||
libpng \
|
||||
libjpeg-turbo \
|
||||
libwebp \
|
||||
freetype \
|
||||
icu \
|
||||
libxml2 \
|
||||
gmp \
|
||||
oniguruma
|
||||
|
||||
# 配置 www.conf
|
||||
RUN sed -i \
|
||||
-e 's/;catch_workers_output = .*/catch_workers_output = yes/g' \
|
||||
-e 's/;php_admin_flag\[log_errors\] = .*/php_admin_flag\[log_errors\] = on/g' \
|
||||
-e 's/;php_admin_value\[error_log\] = .*/php_admin_value\[error_log\] = \/dev\/stderr/g' \
|
||||
/usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
# 配置 PHP 错误日志输出到 stderr
|
||||
RUN echo "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/error-logging.ini
|
||||
|
||||
# 安装 Composer
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
28
.docker/php/entrypoint.sh
Normal file
28
.docker/php/entrypoint.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
ROOT_PATH="/var/www/html"
|
||||
|
||||
SOURCE_DIR="${ROOT_PATH}/nexus/Install/install"
|
||||
TARGET_DIR="${ROOT_PATH}/public"
|
||||
ENV_FILE="${ROOT_PATH}/.env"
|
||||
VENDOR_DIR="${ROOT_PATH}/vendor"
|
||||
#COMPOSER_FILE="${ROOT_PATH}/composer.json"
|
||||
|
||||
# 检查目标文件是否存在
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo "🔧 .env file: $ENV_FILE not exists, copy $SOURCE_DIR to $TARGET_DIR ..."
|
||||
cp -r "$SOURCE_DIR" "$TARGET_DIR"
|
||||
else
|
||||
echo "✅ .env file: $ENV_FILE already exists, skip copy install file ..."
|
||||
fi
|
||||
|
||||
# composer install
|
||||
if [ ! -d "$VENDOR_DIR" ]; then
|
||||
echo "🔧 vendor dir: $VENDOR_DIR not exists, run composer install ..."
|
||||
composer install --working-dir=${ROOT_PATH}
|
||||
else
|
||||
echo "✅ vendor dir: $VENDOR_DIR already exists, skip run composer install ..."
|
||||
fi
|
||||
|
||||
# 最后启动 PHP-FPM
|
||||
exec php-fpm
|
||||
Reference in New Issue
Block a user