步骤:准备环境-复制Python程序-启动程序
为了简单,我们的Python程序就是一个Python文件app.py
app.py
from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return "hello docker" if __name__ == '__main__': app.run(host="0.0.0.0", port=5000)
Dockerfile
FROM python:2.7 LABEL maintainer="Peng Xiao<xiaoquwl@gmail.com>" RUN pip install flask COPY app.py /app/ WORKDIR /app EXPOSE 5000 CMD ["python", "app.py"]
build image 和 启动容器
docker build -t soymilk/python-test .
docker run -d soymilk/python-test