# FastAPI Docker 方式

* Dockfile

```python
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"]
```

* 打包

```bash
docker build -t myfastapi .
```

* 部署

```bash
docker run -d --name myfastapi -p 80:80 myfastapi
```

* 保存镜像

```bash
docker save -o myfastapi.tar myfastapi
```

*   其他机器部署

    ```bash
    docker load < myfastapi.tar
    ```
