首页 > 解决方案 > Why does Docker require PATH when building from custom Dockerfile in another directory?

问题描述

When building docker images with a Dockerfile in the same directory, the following works every time

$ docker build -t project/app:latest .
Sending build context to Docker daemon  135.9MB
...

However, when using -f to specify a different Dockerfile to use, docker complains ...

$ docker build -t project/app:latest -f ../some/path/Dockerfile.other 
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

I can easily provide the PATH, and the build will work, but why is the PATH still required if I'm specifying the absolute path to the Dockerfile with -f?

标签: docker

解决方案


PATH用于指定构建上下文(指令从中复制事物的树)COPY,它不需要与 Dockerfile 的位置有任何关系。

引用文档:

docker build命令从 Dockerfile 和“上下文”构建 Docker 映像。构建的上下文是位于指定PATHURL. 构建过程可以引用上下文中的任何文件。例如,您的构建可以使用COPY指令来引用上下文中的文件。


推荐阅读