From 50d60bf97cf681258c491e305b038fe0d7958b0b Mon Sep 17 00:00:00 2001 From: tangsong Date: Wed, 4 Mar 2026 01:26:56 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9Edocker=E9=83=A8?= =?UTF-8?q?=E5=B1=AC=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++++++++++++++ docker-compose.yml | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ffa2116 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# 使用輕量級的 Python 映像檔 +FROM python:3.11-slim + +# 設定容器內的工作目錄 +WORKDIR /app + +# 先複製需求文件,利用 Docker 快取機制加速打包 +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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5e2bc9f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + discord-bot: + build: . + container_name: my-discord-bot + restart: always # 機器人當掉或伺服器重啟時會自動重啟 + env_file: + - .env # 讀取你的 .env 檔案(如果有的話) + volumes: + - .:/app # (選配) 開發階段可以掛載目錄,修改程式碼不用重新 build + logging: # 限制日誌大小,避免硬碟被塞爆 + driver: "json-file" + options: + max-size: "10mb" + max-file: "3" \ No newline at end of file