docker怎么部署fastapi(docker,fastapi,开发技术)

时间:2024-05-02 17:40:49 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

项目结构:

pycharm结构:

docker怎么部署fastapi

拷贝到xftp时的结构

docker怎么部署fastapi

入口文件:main.py

fromfastapiimportFastAPIapp=FastAPI()@app.get("/index",name="欢迎首页")asyncdefindex():return{"msg":"欢迎来到SayHello!"}

项目依赖:

使用命令可以直接在根目录生成requirements.txt文件

pipfreeze>requirements.txt

requirements.txt 内容如下

aiofiles==0.5.0aniso8601==7.0.0async-exit-stack==1.0.1async-generator==1.10certifi==2021.5.30charset-normalizer==2.0.3click==7.1.2colorama==0.4.4dnspython==2.1.0email-validator==1.1.3fastapi==0.67.0graphene==2.1.9graphql-core==2.3.2graphql-relay==2.0.1h21==0.12.0idna==3.2itsdangerous==1.1.0Jinja2==2.11.3MarkupSafe==2.0.1orjson==3.6.0pip==21.2.1promise==2.3pydantic==1.8.2python-dotenv==0.19.0python-multipart==0.0.5PyYAML==5.4.1requests==2.26.0Rx==1.6.1setuptools==57.4.0six==1.16.0starlette==0.14.2typing-extensions==3.10.0.0ujson==4.0.2urllib3==1.26.6uvicorn==0.13.4watchgod==0.7websockets==8.1

Dockerfile:

FROMpython:3.9.5COPY./appRUNln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtimeRUNecho'Asia/Shanghai'>/etc/timezoneWORKDIR./appRUNpipinstall-rrequirements.txt-ihttps://pypi.tuna.tsinghua.edu.cn/simple/EXPOSE8080CMD["uvicorn","main:app","--host","0.0.0.0","--port","8080"]

xshell进入项目文件列表路径

构建镜像文件(命令结尾的小点“.” 别忘记了)

dockerbuild-t项目名称.

构建成功后运行容器即可:

dockerrun-d--name新取的容器名称-p8000:80刚刚构建的镜像名称
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:docker怎么部署fastapi的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Python如何实现自动整理表格下一篇:

6 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18