Skip to content

Docker:构建Fastapi运行容器

About 530 wordsAbout 2 min

dockerbing-imagesdocker容器构建

2025-02-25

项目使用Python作为编程语言,使用FastAPI作为Web框架,现在需要将写好的项目代码部署到服务器,使用Docker快速部署

一、项目目录结构

├── app
   ├── dto
   ├── forecast
   ├── main.py
   ├── __pycache__
   ├── requirements.txt
   ├── test
   └── test_main.http
├── Dockerfile
└── requirements.txt

二、requirement.txt内容

使用pipreqs来生成requirement.txt文件

pip install pipreqs

pipreqs --ignore .venv --force

--ignore: 忽略执行--force : 强制覆盖requirements.txt的内容

项目使用的是Python Venv的虚拟环境,环境依赖文件直接放到项目中的.venv目录下,开始使用pipreqs来生产requirement.txt,尝试之后没有成功,最后还是切换到当前虚拟环境,使用pip freeze生成requirement.txt.

pip3 freeze > requirements.txt

三、Dockerfile内容

容器中的FastAPI-Docker

构建镜像

docker build -t elm_model .
docker run --name elm_model -p 8000:8000 -itd elm_model

Changelog

Last Updated: View All Changelog
  • feat(wiki): hammeSpoon: 复制出来的文件需要重新生成永链

    On 3/27/25

求求了,快滚去学习!!!

求求了求求了,快去学习吧!

【题单】贪心算法

不知道方向的时候,可以多看看书,书会给你指明下一步该干什么,加油!