使用 `-f Dockerfile` 指定 docker 文件名在构建镜像时产生错误

specify the docker file name with `-f Dockerfile` yields error when building image

我有一个Dockerfile(这个Dockerfile本身没有问题,是第三方提供的)

目录结构:

webapp/
   - Dockfile
   - app.py

我可以通过以下方式构建图像:docker build .它成功构建了一个没有图像名称和标签的图像:

$ docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
<none>                          <none>              ee49229fe570        44 seconds ago      913MB

我想用一个名为“webapp-color”的名称(存储库)构建没有标签的图像。所以,我通过 docker build -f Dockerfile -t webapp-color 重新构建图像,但是这个命令给出了错误:

$ docker build -f Dockerfile -t webapp-color
"docker build" requires exactly 1 argument.
See 'docker build --help'.

然后,我稍微改变了命令,通过执行docker build . -t webapp-color,现在它成功了。

为什么我不能指定 -f Dockerfile?我知道这是 docker 寻找的默认 docker 文件名,但我不明白为什么我不能明确指定它。

我检查了我的 docker 版本:

Docker version 19.03.15

错误不是关于 -f Dockerfile,而是关于最后没有上下文的 PATH (.)。有关详细信息,请参阅 here

This example specifies that the PATH is ., and so all the files in the local directory get tard and sent to the Docker daemon. The PATH specifies where to find the files for the “context” of the build on the Docker daemon. Remember that the daemon could be running on a remote machine and that no parsing of the Dockerfile happens at the client side (where you’re running docker build). That means that all the files at PATH get sent, not just the ones listed to ADD in the Dockerfile.