Docker build gives “unable to prepare context: context must be a directory: /Users/tempUser/git/docker/Dockerfile”

前端 未结 7 1816
野趣味
野趣味 2021-01-31 12:57

I have a Dockerfile that is supposed to build an Ubuntu image. But whenever I run

docker build -t ubuntu-test:latest ./Dockerfile

it shows the fo

7条回答
  •  不思量自难忘°
    2021-01-31 13:31

    Understand contexts

    The docker build command

    The basic syntax of docker's build command is

    docker build -t imagename:imagetag context_dir
    

    The context

    The context is a directory and determines what the docker build process is going to see: From the Dockerfile's point of view, any file context_dir/mydir/myfile in your filesystem will become /mydir/myfile in the Dockerfile and hence during the build process.

    The dockerfile

    If the dockerfile is called Dockerfile and lives in the context, it will be found implicitly by naming convention. That's nice, because it means you can usually find the Dockerfile in any docker container immediately.

    If you insist on using different name, say "/tmp/mydockerfile", you can use -f like this:

    docker build -t imagename:imagetag -f /tmp/mydockerfile context_dir
    

    but then the dockerfile will not be in the same folder or at least will be harder to find.

提交回复
热议问题