From 0d37c28fa2d6464eda9df33b93f5e436908f593a Mon Sep 17 00:00:00 2001 From: youkang <1062424570@qq.com> Date: Thu, 24 Apr 2025 18:41:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0docker-compose=E7=9A=84sqllit?= =?UTF-8?q?e=E9=83=A8=E7=BD=B2=E6=96=B9=E6=A1=88=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E9=80=82=E7=94=A8=E4=BA=8E=E6=96=B0=E6=89=8B=E7=94=A8=E6=88=B7?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96Dockerfile=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=95=9C=E5=83=8F=E6=BA=90=E5=8A=A0=E9=80=9F?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - Dockerfile | 24 +++++++++++++++++------- README.md | 31 +++++++++++++++++++++++++++++++ docker-compose-sqllite.yml | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 docker-compose-sqllite.yml diff --git a/.dockerignore b/.dockerignore index c5602018..5808b917 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,7 +13,6 @@ tests/ .gitignore .pre-commit-config.yaml .prettier* -.env.dev docker-compose.yml Dockerfile LICENSE diff --git a/Dockerfile b/Dockerfile index acdbd5fd..fa4dde63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,11 @@ WORKDIR /tmp ENV POETRY_HOME="/opt/poetry" PATH="${PATH}:/opt/poetry/bin" +RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ && \ + pip install --upgrade pip + RUN curl -sSL https://install.python-poetry.org | python - -y && \ - poetry self add poetry-plugin-export + poetry self add poetry-plugin-export COPY ./pyproject.toml ./poetry.lock* /tmp/ @@ -22,6 +25,8 @@ WORKDIR /wheel COPY --from=requirements-stage /tmp/requirements.txt /wheel/requirements.txt # RUN python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ && \ + pip install --upgrade pip RUN pip wheel --wheel-dir=/wheel --no-cache-dir --requirement /wheel/requirements.txt @@ -44,12 +49,17 @@ ENV TZ=Asia/Shanghai PYTHONUNBUFFERED=1 EXPOSE 8080 -RUN apt update && \ - apt install -y --no-install-recommends curl fontconfig fonts-noto-color-emoji \ - && apt clean \ - && fc-cache -fv \ - && apt-get purge -y --auto-remove curl \ - && rm -rf /var/lib/apt/lists/* +# 1. 确保目录存在 +RUN mkdir -p /etc/apt/sources.list.d +# 2. 直接写入清华源(主源+安全源) +RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \ + apt update && \ + apt install -y --no-install-recommends curl fontconfig fonts-noto-color-emoji && \ + apt clean && \ + fc-cache -fv && \ + apt-get purge -y --auto-remove curl && \ + rm -rf /var/lib/apt/lists/* # 复制依赖项和应用代码 COPY --from=build-stage /wheel /wheel diff --git a/README.md b/README.md index 83987f0d..4b459656 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,37 @@ poetry install # 安装依赖 poetry run python bot.py ``` +## 🛠️ Docker-Compose部署(以SqlLite为例) + +```bash +# 获取代码 +git clone https://github.com/HibiKier/zhenxun_bot.git + +# 修改.env.dev配置文件 +DB_URL = "sqlite:data/db/zhenxun.db" # 根据自行需求配置地址 +HOST = 0.0.0.0 + +# 进入目录 +cd zhenxun_bot + +# 启动容器 +docker-compose -f docker-compose-sqllite.yml up -d +# docker-compose -f docker-compose-sqllite.yml up -d --build(这个是重新构建镜像) + +# 等待容器创建完成(中间可能由于后面的操作没有完成会一直自动重启) + +# 容器创建成功后会在当前目录下创建一个DockerData目录 +# 创建目录/DockerData/data/db +# 将/data/config.yaml文件复制到/DockerData/data/config.yaml +# 配置/DockerData/data/config.yaml中的WebUI账号密码 +web-ui: + USERNAME: admin + PASSWORD: + +# 重启容器等一下资源文件下载完成就可以打开WebUI了 +# 如果资源文件下载失败,可以手动下载到/DockerData/resources目录下 +``` + ## 📝 简单配置 > [!TIP] diff --git a/docker-compose-sqllite.yml b/docker-compose-sqllite.yml new file mode 100644 index 00000000..3250811e --- /dev/null +++ b/docker-compose-sqllite.yml @@ -0,0 +1,15 @@ +services: + zhenxun: + image: zhenxun + build: . + container_name: zhenxun + restart: unless-stopped + privileged: true + ports: + - "8080:8080" + volumes: + - $PWD/DockerData/data:/app/zhenxun/data + - $PWD/DockerData/resources:/app/zhenxun/resources + - $PWD/DockerData/log:/app/zhenxun/log + tty: true + stdin_open: true \ No newline at end of file