diff --git a/Dockerfile b/Dockerfile index ffa2116..4a05c97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,20 @@ -# 使用輕量級的 Python 映像檔 +# 使用 Python 映像檔 FROM python:3.11-slim -# 設定容器內的工作目錄 +# 更新系統並安裝 FFmpeg +RUN apt-get update && \ + apt-get install -y ffmpeg && \ + rm -rf /var/lib/apt/lists/* + +# 設定工作目錄 WORKDIR /app -# 先複製需求文件,利用 Docker 快取機制加速打包 +# 複製並安裝 Python 套件 COPY requirements.txt . - -# 安裝必要的套件 RUN pip install --no-cache-dir -r requirements.txt -# 複製其餘的程式碼到容器內 +# 複製程式碼 COPY . . -# 執行你的 Discord Bot -CMD ["python", "discord-bot.py"] \ No newline at end of file +# 執行 Bot,加上 -u 確保輸出不被快取 +CMD ["python", "-u", "discord-bot.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5e2bc9f..c8bc826 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,9 +2,13 @@ services: discord-bot: build: . container_name: my-discord-bot - restart: always # 機器人當掉或伺服器重啟時會自動重啟 + restart: always + tty: true # 模擬終端機 + stdin_open: true # 開啟標準輸入 + environment: + - PYTHONUNBUFFERED=1 # 強制 Python 立即輸出,不進行快取 env_file: - - .env # 讀取你的 .env 檔案(如果有的話) + - .env volumes: - .:/app # (選配) 開發階段可以掛載目錄,修改程式碼不用重新 build logging: # 限制日誌大小,避免硬碟被塞爆