測試 docker 完整流程 20250528

This commit is contained in:
allen.yan 2025-05-28 14:28:45 +08:00
parent e72f595998
commit c85a14e5f7
6 changed files with 81 additions and 7 deletions

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
# Dockerfile
# 基礎 PHP + Node + Composer
FROM php:8.3-fpm
# 安裝系統套件與 PHP 擴充
RUN apt-get update && apt-get install -y \
git unzip curl libzip-dev zip libpng-dev libonig-dev cron supervisor \
&& docker-php-ext-install pdo pdo_mysql zip
# 安裝 Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 安裝 Node.js 與 npm
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y nodejs
# 建立 Laravel 專案目錄
WORKDIR /var/www/html
# 複製 supervisord 設定與啟動腳本
COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# 啟動腳本
CMD ["/usr/local/bin/entrypoint.sh"]

View File

@ -1,9 +1,10 @@
services: services:
app: app:
image: php:8.3-fpm build:
context: .
dockerfile: Dockerfile
container_name: KTVCentral container_name: KTVCentral
working_dir: /var/www/html
volumes: volumes:
- ./:/var/www/html - ./:/var/www/html
depends_on: depends_on:
@ -15,7 +16,6 @@ services:
DB_DATABASE: Karaoke-Kingpin DB_DATABASE: Karaoke-Kingpin
DB_USERNAME: Karaoke-Kingpin DB_USERNAME: Karaoke-Kingpin
DB_PASSWORD: ESM7yTPMnavFmbBH DB_PASSWORD: ESM7yTPMnavFmbBH
command: php-fpm
mariadb: mariadb:
image: mariadb:10.6 image: mariadb:10.6

16
docker/entrypoint.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# 啟動前置作業
cd /var/www/html
composer install
cp .env.example .env
php artisan key:generate
npm install && npm run build
php artisan migrate --force
# 加入 Laravel 排程至 cron
echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" | crontab -
# 啟動 Supervisor
exec supervisord -n

View File

@ -1,10 +1,10 @@
server { server {
listen 80; listen 80;
index index.php index.html; server_name ktvcentral.localhost;
server_name localhost;
root /var/www/html/public; root /var/www/html/public;
index index.php index.html;
location / { location / {
try_files $uri $uri/ /index.php?$query_string; try_files $uri $uri/ /index.php?$query_string;
} }
@ -13,7 +13,8 @@ server {
include fastcgi_params; include fastcgi_params;
fastcgi_pass app:9000; fastcgi_pass app:9000;
fastcgi_index index.php; fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/public$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
} }
location ~ /\.ht { location ~ /\.ht {

28
docker/supervisord.conf Normal file
View File

@ -0,0 +1,28 @@
[supervisord]
nodaemon=true
[program:php-fpm]
command=docker-php-entrypoint php-fpm
autostart=true
autorestart=true
priority=1
[program:queue-worker]
command=php /var/www/html/artisan queue:work --daemon --timeout=3600 --tries=1 --queue=default
autostart=true
autorestart=true
priority=2
stdout_logfile=/var/www/html/storage/logs/queue.log
stderr_logfile=/var/www/html/storage/logs/queue_error.log
[program:schedule-run]
command=cron -f
autostart=true
autorestart=true
priority=3
[program:sqlite-sync]
command=php /var/www/html/artisan transfer:sqlite sqlite/tempUser.sqlite --sync
autostart=true
autorestart=false
priority=4

View File

@ -88,3 +88,5 @@ php artisan make:job TransferSqliteTableJob
php artisan migrate:rollback php artisan migrate:rollback
php artisan migrate php artisan migrate
php artisan transfer:sqlite sqlite/tempUser.sqlite --sync php artisan transfer:sqlite sqlite/tempUser.sqlite --sync
php artisan queue:work --daemon --timeout=3600 --tries=1 --queue=default