dockerfile

This commit is contained in:
浪子
2026-03-19 19:39:14 +08:00
parent 04eccc850d
commit 62cffc6f5f
13 changed files with 578 additions and 51 deletions
+95
View File
@@ -43,6 +43,101 @@ composer run setup
composer run dev
```
## Docker
仓库已提供通用容器化文件:
- `Dockerfile`
- `.dockerignore`
- `docker/apache/000-default.conf`
- `docker/entrypoint.sh`
- `docker/php/opcache.ini`
- `docker-compose.example.yml`
### 1. 构建镜像
```bash
docker build -t tstore:latest .
```
这个镜像是多阶段构建,包含:
- Composer 依赖安装
- Vite 前端资源构建
- Apache + PHP 8.2 运行时
容器内网站根目录已经指向 `public/`,不需要再额外改 Web 根目录。
### 2. 单容器运行
更适合已经有外部 MySQL 的场景。
```bash
docker run -d \
--name tstore \
-p 8080:80 \
--env-file .env \
-e APP_ENV=production \
-e APP_DEBUG=false \
-e APP_URL=http://localhost:8080 \
-e LOG_CHANNEL=stderr \
-e DB_CONNECTION=mysql \
-e DB_HOST=your-db-host \
-e DB_PORT=3306 \
-e DB_DATABASE=tstore \
-e DB_USERNAME=tstore \
-e DB_PASSWORD=your-password \
-e SESSION_DRIVER=file \
-e CACHE_STORE=file \
-e QUEUE_CONNECTION=sync \
-e RUN_MIGRATIONS=1 \
-e RUN_OPTIMIZE=1 \
tstore:latest
```
如果你希望容器启动时自动创建后台管理员账号,可以再加:
```bash
-e RUN_ADMIN_SEEDER=1
```
说明:
- `RUN_MIGRATIONS=1` 会在容器启动时执行 `php artisan migrate --force`
- `RUN_ADMIN_SEEDER=1` 会执行 `AdminUserSeeder`
- `RUN_OPTIMIZE=1` 会执行 `php artisan optimize`
### 3. 使用 Docker Compose
仓库提供了一个通用示例文件:
```bash
cp docker-compose.example.yml docker-compose.yml
docker compose up -d --build
```
默认暴露端口:
- 应用:`8080`
- MySQL:不对宿主机暴露,仅供容器内部访问
首次启动前,建议先修改:
- `docker-compose.yml` 中的数据库密码
- `.env` 中的 `APP_URL`
- `.env` 中的 `SESSION_DRIVER`、`CACHE_STORE`、`QUEUE_CONNECTION`
- `.env` 中的 `STORE_ADMIN_TOKEN`
- `.env` 中的 `STORE_PLUGIN_ACCESS_TOKEN`
- `.env` 中的 `ADMIN_EMAIL`
- `.env` 中的 `ADMIN_PASSWORD`
### 4. 容器化运行时建议
- 生产环境优先使用 MySQL,不建议继续使用 SQLite
- 如果要持久化上传的 ZIP 包和日志,保留 `storage` 卷挂载
- 不要把真实 `.env` 打进镜像,运行时通过 `--env-file` 或 Compose 注入
- 如果上线到生产,建议把 `APP_URL` 改成正式域名,并在网关层处理 HTTPS
## 生产部署
以下步骤以 `Linux + Nginx + PHP-FPM` 为例。生产环境不要运行 `php artisan serve` 和 `npm run dev`。