1.前几天我看官方文档,在第二部分,写好了app.py跟dockerfile,还有requirements.txt.
2.运行时输入:docker bulid -t dockerdemo .
最后报错。不知道为什么,大致记得报错提示是docker Collecting Flask (from -r requirements.txt (line 1))
3.然后接着现在输入docker bulid -t friendlyhello .就运行通过了。
求大佬解释这其中原因。
运行环境:Docker for Mac
版本:Docker version 17.06.1-ce, build 874a737
重点:app.py和dockerfile还有requirements.txt都没有任何变化。
附上app.py代码
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
@app.route("/")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "cannot connect to Redis, counter disabled"
html = "
Hello {name}!
" \"Hostname: {hostname}
" \
"Visits: {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
附上dockerfile代码
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
附上requirements.txt
Flask
Redis
求大佬解释其中问题