镜像更换
This commit is contained in:
parent
d98a0e3d4c
commit
c2801e9686
55
Dockerfile
55
Dockerfile
|
|
@ -1,39 +1,52 @@
|
|||
# PHP-FPM镜像
|
||||
FROM webdevops/php:8.2-fpm
|
||||
# 使用官方镜像并配置国内加速
|
||||
FROM php:8.2-fpm
|
||||
|
||||
# 使用阿里云镜像源
|
||||
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
|
||||
&& sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
|
||||
|
||||
# 安装依赖时添加--no-install-recommends减少不必要的包
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
# 配置阿里云镜像源
|
||||
RUN set -eux; \
|
||||
# 系统源更换
|
||||
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
|
||||
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
|
||||
# 安装基础工具
|
||||
apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
zip \
|
||||
unzip \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
libonig-dev \
|
||||
libxml2-dev \
|
||||
# 合并扩展安装命令
|
||||
&& docker-php-ext-install -j$(nproc) pdo_mysql mbstring exif pcntl bcmath gd sockets zip \
|
||||
# 清理缓存减少镜像体积
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
libxml2-dev; \
|
||||
# 批量安装核心扩展(移除非常用扩展)
|
||||
docker-php-ext-configure zip; \
|
||||
docker-php-ext-install -j$(nproc) \
|
||||
pdo_mysql \
|
||||
mbstring \
|
||||
bcmath \
|
||||
gd \
|
||||
zip; \
|
||||
# 清理缓存
|
||||
apt-get clean; \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*;
|
||||
|
||||
# 安装Composer
|
||||
# 配置Composer国内镜像
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
|
||||
|
||||
WORKDIR /var/www
|
||||
|
||||
# 先复制依赖文件利用缓存
|
||||
COPY composer.json composer.lock ./
|
||||
|
||||
# 安装生产依赖(不安装dev依赖)
|
||||
RUN composer install --no-dev --optimize-autoloader --no-scripts
|
||||
|
||||
# 复制项目文件
|
||||
COPY . .
|
||||
|
||||
RUN composer install --no-dev --optimize-autoloader
|
||||
# 设置存储目录权限
|
||||
RUN chown -R www-data:www-data storage
|
||||
RUN chmod -R 775 storage
|
||||
|
||||
# 设置权限
|
||||
RUN chown -R www-data:www-data /var/www/storage
|
||||
RUN chmod -R 775 /var/www/storage
|
||||
|
||||
# Nginx配置
|
||||
# 多阶段构建Nginx
|
||||
FROM nginx:alpine
|
||||
COPY --from=0 /var/www /var/www
|
||||
COPY .docker/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
|
|
|||
Loading…
Reference in New Issue