构建 Flask 应用程序的 docker 图像时出错

Error while building a docker image of a flask app

这是烧瓶应用程序:

`From flask import Flask
 app = Flask(__name__)

 @app.route('/')
 def hello_world():
    return 'Flask Dockerized'

 if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0')`

这是 docker 文件:

FROM ubuntu:14.04 
MAINTAINER Ashish John Stanley "a*********@gmail.com"    
RUN apt-get update -y  RUN apt-get install -y python-pip python-dev build-essential  
COPY . /app  WORKDIR /app  RUN pip install -r requirements.txt
ENTRYPOINT ["python"]    
CMD ["app.py"]

构建 docker 文件的命令:

docker build -t flask-container:latest. -f --file="~/Documents/web/requirements.txt"

执行命令出现如下错误terminal screenshot

--file 应该指向包含 Dockerfile

的目录

这是为您的案例创建 docker 图片的命令:

docker build -t flask-container:latest .

确保你是 运行 它来自包含 Dockerfile

的目录

Docker 文档:

--file , -f       Name of the Dockerfile (Default is ‘PATH/Dockerfile’)

By default the docker build command will look for a Dockerfile at the root of the build context. The -f, --file, option lets you specify the path to an alternative file to use instead. This is useful in cases where the same set of files are used for multiple builds. The path must be to a file within the build context. If a relative path is specified then it is interpreted as relative to the root of the context.

这里是关于 Docker 选项的更多信息

https://docs.docker.com/engine/reference/commandline/build/#options.