Building docker image for python app

1 min read–

Dockerfile

FROM python:3.9-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]

Sample Flask app to try containerize

from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

port = 5100

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=port)

and then start the app using

python app.py

I am using slim image instead of alpine. Good article on why not to use alpine for python. Official Docker docs for building python image.

Webmentions