Docker:不读文件

我正在构build一个简单的应用程序: Dockerfileapp.pyrequirements.txt 。 当Dockerfile生成时,我得到错误:“没有这样的文件或目录”。 但是,当我更改添加到复制在Dockerfile它的作品。 你知道这是为什么吗?

我正在使用教程: https : //docs.docker.com/get-started/part2/#define-a-container-with-a-dockerfile

错误 错误修复

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) 

requirements.txt

 Flask Redis 

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"] 

在第一次运行中,您的工作目录是/app内的容器,并且将内容复制到/tmp 。 要改正这种行为,你应该将内容复制到/app ,它会正常工作。

第二个,你正在使用add是正确的,因为你正在添加内容到/app 。,而不是/tmp