添加容器化

This commit is contained in:
coolxitech 2024-10-29 14:07:53 +08:00
parent 5e25fb2726
commit 45c0f0f0b5
2 changed files with 34 additions and 0 deletions

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3.8'
services:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/html # 将当前目录挂载到容器
command: php think run # 启动 PHP 内置服务器
ports:
- "8000:8000" # 映射容器端口到主机端口

22
dockerfile Normal file
View File

@ -0,0 +1,22 @@
# 使用 PHP 8.1 镜像
FROM php:8.1-cli
# 安装 OPcache 扩展
RUN apt-get update && apt-get install -y libzip-dev \
&& docker-php-ext-install opcache \
&& docker-php-ext-install pdo pdo_mysql
# 拷贝项目文件到容器
COPY . /var/www/html/
# 设置工作目录
WORKDIR /var/www/html/
# 安装 Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 安装项目依赖
RUN composer install --no-interaction
# 配置 OPcache
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini