使用 Docker 容器化 FastAPI 專案 Memo's Blog 2024-08-28 Deployment Deployment, Docker, FastAPI, Python 實作新增 Dockerfile 檔。 123456789101112131415FROM python:3.12-slimWORKDIR /appRUN pip install --no-cache-dir poetryCOPY pyproject.toml poetry.lock ./RUN poetry install --no-rootCOPY . .CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]EXPOSE 80 新增 docker-compose.yml 檔。 1234567891011version: '3.8'services: app: build: context: . dockerfile: Dockerfile ports: - "80:80" environment: - PYTHONUNBUFFERED=1 啟動服務。 1docker compose up -d