Docker for Mac 终端下用docker build -t friendlyhello . 的问题

新手上路,请多包涵

1.前几天我看官方文档,在第二部分,写好了app.pydockerfile,还有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.pydockerfile还有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 = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {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

求大佬解释其中问题

阅读 4.3k
1 个回答

build的会执行Run指令,如果遇到网络超时,或者啥的build会挂掉,日志不全,大概可能就是这些问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题