docker怎么部署fastapi
导读:本文共1195字符,通常情况下阅读需要4分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 项目结构:pycharm结构:拷贝到xftp时的结构入口文件:main.pyfromfastapiimportFastAPIapp=FastAPI()@app.get("/index",name="欢迎首页")asyncdefindex():return{"msg":"欢迎来到Sa... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。项目结构:
pycharm结构:
拷贝到xftp时的结构
入口文件: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的详细内容,希望对您有所帮助,信息来源于网络。