2025-05-25 14:16:56 +08:00
2025-05-23 15:09:01 +08:00
2025-05-23 15:09:01 +08:00
2025-05-23 15:04:32 +08:00
2025-05-25 14:16:56 +08:00
2025-05-25 14:16:56 +08:00
2025-05-23 15:04:32 +08:00
2025-05-25 14:16:56 +08:00
2025-05-23 15:04:32 +08:00
2025-05-23 15:04:32 +08:00

Python Docker 示例项目

这是一个使用 FastAPI 构建的简单 Python Web 应用程序的示例项目,并使用 Docker 进行容器化。

项目结构

.
├── Dockerfile          # Docker 配置文件
├── main.py             # FastAPI 应用程序入口
├── pyproject.toml      # 项目元数据和依赖项 (PEP 621)
├── README.md           # 本文档
└── uv.lock             # uv 生成的锁定文件,确保依赖版本一致

先决条件

在开始之前,请确保您已安装以下软件:

  • Python 3.11 或更高版本
  • uv (Python 包安装器)
  • Docker (用于容器化)

安装

  1. 克隆仓库:

    git clone <your-repository-url>
    cd python-docker-example
    
  2. 安装依赖项:

    uv sync
    

运行应用程序

本地运行 (使用 Uvicorn)

您可以使用 Uvicorn 直接运行 FastAPI 应用程序:

uv run uvicorn main:app --reload

应用程序将在 http://127.0.0.1:8000 上可用。

使用 Docker

构建 Docker 镜像

docker build -t python-docker-example .

运行 Docker 容器

docker run -p 8000:8000 python-docker-example

应用程序将在 http://localhost:8000 上可用。

S
Description
No description provided
Readme
59 KiB
Languages
Python 90.8%
Dockerfile 9.2%