FastAPI Docker 方式

  • Dockfile

FROM python:3.9.9-alpine

RUN pip install fastapi uvicorn aiofiles fastapi-async-sqlalchemy python-multipart

EXPOSE 80

COPY . .

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
  • 打包

docker build -t myfastapi .
  • 部署

docker run -d --name myfastapi -p 80:80 myfastapi
  • 保存镜像

docker save -o myfastapi.tar myfastapi
  • 其他机器部署

    docker load < myfastapi.tar

Last updated