FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY ./app /app
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
.
├── app
│ └── main.py
└── Dockerfile
$ docker build -t fastapi_image .
$ docker run -d --name fastapi_container -p 80:80 fastapi_image
$ docker run -d --name fastapi_container -p 8080:80 fastapi_image