dragg2 commited on
Commit
965692e
·
verified ·
1 Parent(s): def0d3b

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -0
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 步骤 1: 选择一个合适的 Python 基础镜像。python:3.11-slim 是一个稳定且轻量的选择。
2
+ FROM python:3.11-slim
3
+
4
+ # 步骤 2: 安装 git,以便我们可以从 GitHub 克隆代码。
5
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
6
+
7
+ # 步骤 3: 设置容器内的工作目录。
8
+ WORKDIR /app
9
+
10
+ # 步骤 4: 克隆项目代码。关键在于使用 "-b light" 来指定克隆 "light" 分支。
11
+ # 末尾的 "." 表示将代码克隆到当前工作目录 (/app) 内。
12
+ RUN git clone -b light https://github.com/VeroFess/grok2api.git .
13
+
14
+ # 步骤 5: 安装项目所需的 Python 依赖库。
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
+
17
+ # 步骤 6: (推荐) 预先设置整个应用目录的权限,避免任何潜在的权限问题。
18
+ # 这是一个好习惯,可以防止应用因尝试写入日志或其他文件而被拒绝。
19
+ RUN chmod -R 777 /app
20
+
21
+ # 步骤 7: 暴露端口。根据 README 中的 docker-compose.yml 示例,我们知道应用在 8080 端口上运行。
22
+ EXPOSE 8080
23
+
24
+ # 步骤 8: 设置容器启动命令。
25
+ # README 中的 docker-compose.yml 文件明确指出使用 uvicorn 启动,这是在容器中运行 FastAPI 应用的标准方式。
26
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]