Docker构build提供了“无法准备上下文:上下文必须是一个目录:/ Users / tempUser / git / docker / Dockerfile”
我有一个应该build立一个Ubuntu
镜像的Dockerfile
。 但是,当我跑步
docker build -t ubuntu-test:latest ./Dockerfile
它在控制台上显示以下错误
unable to prepare context: context must be a directory: /Users/tempUser/git/docker/Dockerfile
我在Mac OsX上。 我也尝试sudo
。 没什么工作。
我做了docker build -t ubuntu-test:latest .
而不是docker build -t ubuntu-test:latest ./Dockerfile
,它的工作。
要在构build时指定Dockerfile
,可以使用:
docker build -t ubuntu-test:latest - < /path/to/your/Dockerfile
但是,如果有ADD
或COPY
命令取决于相对path,则会失败。 有很多方法可以为docker build
指定一个context
,你可以参考docker build的文档来获取更多的信息。
你也可以用-f
选项运行docker build
docker build -t ubuntu-test:latest -f Dockerfile.custom .
I face the same issue. I am using docker version:17.09.0-ce. I follow below steps. Step 1: create Dockerfile and added commands for creating docker image Step 2: go to directory where we have created Dockfile Step 3: execute below command $sudo docker build -t ubuntu-test:latest . It resolved issue and image created successsfully Note: build command depend on docker version as well as which build option we are using. :)