【发布时间】:2017-09-15 13:58:04
【问题描述】:
我正在使用Dockerfile、app.py 和requirements.txt 构建一个简单的应用程序。当 Dockerfile 构建时,我收到错误:“没有这样的文件或目录”。但是,当我在 Dockerfile 中将 ADD 更改为 COPY 时,它可以工作。你知道这是为什么吗?
我正在使用教程:https://docs.docker.com/get-started/part2/#define-a-container-with-a-dockerfile
应用程序.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"]
【问题讨论】:
-
你能显示两个构建的日志吗?
-
复制了你的 Dockerfile,并尝试构建,一切正常,你的
requirements.txt和Dockerfile?
标签: python docker cmd dockerfile