背景
最近工作需要,用Dockerfile来构建镜像,找来的文档如下
https://yeasy.gitbooks.io/docker_practice/content/image/build.html
$ docker build -t nginx:v3 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM nginx
---> e43d811ce2f4
Step 2 : RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
---> Running in 9cdc27646c7b
---> 44aa4490ce2c
Removing intermediate container 9cdc27646c7b
Successfully built 44aa4490ce2c
照敲提示报错,
$ docker build -t centos_base:v1
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | - [flags]
Build an image from a Dockerfile
感觉这其中必有蹊跷啊~
解决
按照问题处置标准流程?一字一字比对,发觉最后有一个点 .
??
后续
在官方文档找到了这样一段描述
https://docs.docker.com/engine/reference/commandline/build/ 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.
# USAGE
docker build [OPTIONS] PATH | URL | -
# e.g.
docker build .
意思是说,在官方文档的示例里,PATH
指明了.
,然后在当前目录下的多有文件都被发送进了Docker的守护进程,PATH
指定了构建镜像时上下文查找文件的路径。比如Dockerfile 里ADD
指令的第一个参数可以从上下文也就是刚刚发送进Docker Daemon的文件中找到。
?写这篇为了说明啥,说明执行结果不在预期时,要更加关注平时会忽略的地方~