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

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

求大佬解释其中问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值