initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# Python Docker 示例项目
|
||||
|
||||
这是一个使用 FastAPI 构建的简单 Python Web 应用程序的示例项目,并使用 Docker 进行容器化。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```bash
|
||||
.
|
||||
├── Dockerfile # Docker 配置文件
|
||||
├── main.py # FastAPI 应用程序入口
|
||||
├── pyproject.toml # 项目元数据和依赖项 (PEP 621)
|
||||
├── README.md # 本文档
|
||||
└── uv.lock # uv 生成的锁定文件,确保依赖版本一致
|
||||
```
|
||||
|
||||
## 先决条件
|
||||
|
||||
在开始之前,请确保您已安装以下软件:
|
||||
|
||||
- Python 3.11 或更高版本
|
||||
- uv (Python 包安装器)
|
||||
- Docker (用于容器化)
|
||||
|
||||
## 安装
|
||||
|
||||
1. 克隆仓库:
|
||||
|
||||
```bash
|
||||
git clone <your-repository-url>
|
||||
cd python-docker-example
|
||||
```
|
||||
|
||||
2. 安装依赖项:
|
||||
```bash
|
||||
uv sync
|
||||
```
|
||||
|
||||
## 运行应用程序
|
||||
|
||||
### 本地运行 (使用 Uvicorn)
|
||||
|
||||
您可以使用 Uvicorn 直接运行 FastAPI 应用程序:
|
||||
|
||||
```bash
|
||||
uv run uvicorn main:app --reload
|
||||
```
|
||||
|
||||
应用程序将在 `http://127.0.0.1:8000` 上可用。
|
||||
|
||||
## 使用 Docker
|
||||
|
||||
### 构建 Docker 镜像
|
||||
|
||||
```bash
|
||||
docker build -t python-docker-example .
|
||||
```
|
||||
|
||||
### 运行 Docker 容器
|
||||
|
||||
```bash
|
||||
docker run -p 8000:8000 python-docker-example
|
||||
```
|
||||
|
||||
应用程序将在 `http://localhost:8000` 上可用。
|
||||
Reference in New Issue
Block a user