一起构建一个 Python Flask 镜像

Python 程序

  1. from flask import Flask
  2. app = Flask(__name__)
  3. @app.route('/')
  4. def hello_world():
  5. return 'Hello, World!'

Dockerfile

  1. FROM python:3.9.5-slim
  2. COPY app.py /src/app.py
  3. RUN pip install flask
  4. WORKDIR /src
  5. ENV FLASK_APP=app.py
  6. EXPOSE 5000
  7. CMD ["flask", "run", "-h", "0.0.0.0"]