測試 docker 完整流程 20250528
This commit is contained in:
parent
e72f595998
commit
c85a14e5f7
27
Dockerfile
Normal file
27
Dockerfile
Normal 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"]
|
@ -1,9 +1,10 @@
|
||||
|
||||
services:
|
||||
app:
|
||||
image: php:8.3-fpm
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: KTVCentral
|
||||
working_dir: /var/www/html
|
||||
volumes:
|
||||
- ./:/var/www/html
|
||||
depends_on:
|
||||
@ -15,7 +16,6 @@ services:
|
||||
DB_DATABASE: Karaoke-Kingpin
|
||||
DB_USERNAME: Karaoke-Kingpin
|
||||
DB_PASSWORD: ESM7yTPMnavFmbBH
|
||||
command: php-fpm
|
||||
|
||||
mariadb:
|
||||
image: mariadb:10.6
|
||||
|
16
docker/entrypoint.sh
Normal file
16
docker/entrypoint.sh
Normal 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
|
@ -1,10 +1,10 @@
|
||||
server {
|
||||
listen 80;
|
||||
index index.php index.html;
|
||||
server_name localhost;
|
||||
|
||||
server_name ktvcentral.localhost;
|
||||
root /var/www/html/public;
|
||||
|
||||
index index.php index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
@ -13,7 +13,8 @@ server {
|
||||
include fastcgi_params;
|
||||
fastcgi_pass app:9000;
|
||||
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 {
|
||||
|
28
docker/supervisord.conf
Normal file
28
docker/supervisord.conf
Normal 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
|
Loading…
x
Reference in New Issue
Block a user