Flask Docker Hello Word

環境

Docker
Flask

代碼

新建 app.py 文件python

From flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Flask Docker Hello Word'

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0')

新建 requirements.txt 文件docker

Flask==0.10.1

Dockerfile

新建 Dockerfileflask

FROM ubuntu:latest
MAINTAINER dingdayu "6144220992@qq.com"

RUN sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.aliyun\.com\/ubuntu\//g' /etc/apt/sources.list

RUN apt-get -qqy update && \
	apt-get install -y python-pip python-dev build-essential && \
	rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

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

編譯

docker build -t flask-docker-hello:latest .

運行

docker run -d -p 5000:5000 flask-docker-hello
相關文章
相關標籤/搜索