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 2023-08-18 19:02  06  阅读(397)  评论(0编辑  收藏  举报