目錄結(jié)構(gòu)
app.py Dockerfile requirements.txt
app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
@app.route("/home")
def home():
return "<h1>Home Page</h1>"
app.run(debug=True,host='0.0.0.0', port=80)
注意:ip地址填0.0.0.0 而不是填你本地非docker環(huán)境正常跑的局域網(wǎng)ip地址
requirements.txt
Flask==1.0.2
Dockerfile
FROM python:3-alpine
MAINTAINER luli
WORKDIR /app
ADD . /app
RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
EXPOSE 80
CMD ["python3","app.py"]
Docker 編譯、啟動腳本
docker build -t pytest2-1 .
docker run -d --name pyt -p 4000:80 pytest2-1