API 서버 앱 준비

# ./src/main.py
from sanic import Sanic
from sanic.response import json

app = Sanic(name="My API Server")

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)
# ./requirements.txt
sanic==19.12.2

Dockerfile 작성하기

FROM ubuntu
FROM python
MAINTAINER TaewooLee "oiehot@gmail.com"
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["src/main.py"]

빌드 및 실행

$ docker build -t my-api-server:latest .
$ docker run -d -p 5000:5000 my-api-server

참고자료