随笔 - 105  文章 - 2 评论 - 9 阅读 - 19万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

uvicorn 项目接触比较少,写dockerfile编译后,启动一直报错重启,尤其是最后写 ENTRYPOINT 启动命令,改了很多次,特地记录下。

以下为正确的dockerfile文件

FROM python:latest
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple fastapi[all]
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docxtpl
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pycrypto
RUN mkdir -p /report_tpl
WORKDIR /report_tpl
ADD . /report_tpl
ENTRYPOINT [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3333"]

注:

1.RUN pip install -i 要替换成国内的源,要不然下载插件速度很慢,,例如阿里源,豆瓣源等,这里用清华源

2.最后的--host,--port 一定要和参数分开写,要不然会报错无效参数--host,--port 

3.main:app要指向main.py所在目录,这里设置了workdir,所以和main.py在同级目录,如果不同级要写成 ${dir}.main:app

 

 

参考文档:

https://www.5axxw.com/questions/content/zp0i2p

https://www.5axxw.com/questions/content/om23jf

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

posted on   06  阅读(507)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示