docker - Docker 构建上下文的目的是什么?

Docker 构建上下文的目的是什么?我从文档中了解到,它是将整个内容发送到 docker 守护进程的“入口”点。但是,发送当前目录的全部内容有什么意义呢?如果上下文被发送到守护进程以包含在图像中,那么为什么我们需要做这个额外的步骤。为什么压缩后的上传/发送/复制任务默认不包含指定目录的内容?

例如给定这个目录结构

-rw-r--r--  1 me me    7 Jun  8 18:52 .dockerignore
-rw-r--r--  1 me me 1.1K Jun  9 12:42 Dockerfile
drwxr-xr-x 13 me me 4.0K Jun  8 19:43 myproject

当我运行这个命令时 docker build -t user/myproject:2.3 .

然后我希望在生成的图像中的某处看到一个 myproject 目录。但是,我必须包括

 ADD myproject /

就是这样。

如果构建过程压缩当前目录内容并将其发送给守护进程,它会去哪里?为什么它不使该内容可在图像中使用?

最佳答案

TL;DR:“因为客户端和守护程序甚至可能不在同一台机器上运行”

docker 命令是dockerddocker 客户端,是可以直接在你的PC(linux)或下面运行的服务OSX 或 Windows 下的 Linux VM。

Q: What is the purpose of the Docker build context?

来自 here :

Would probably be good to also mention that this has to happen this way because the client and daemon may not even run on the same machine, so without this "context" the daemon machine wouldn't have any other way to get files for ADD or otherwise


Q: If the build process compresses the current directory contents and sends it to the daemon, where does it go?

docker daemon 接收压缩目录并即时处理它;在那一刻它存储在哪里并不重要。

Q: Why doesn't it make that content available for use in the image?

想一想:docker 怎么知道想把每个文件/目录放在目标镜像中的什么位置?使用 COPY/ADD 指令,您可以控制每个指令的放置位置。你提到的情况只是一个简单的例子,你有一个目录和一个目标。

https://stackoverflow.com/questions/44465703/

相关文章:

haskell - 使用 cabal 和 ghc 构建运行时标志

c - 如何链接到 C 中的静态库?

c - getopt.h : Compiling Linux C-Code in Windows

javascript - 如何防止 Visual Studio 2017 构建 JavaScript

c++ - 如何在 CMake 中正确创建目标之间的依赖关系?

asp.net - Web.config 构建与发布转换不起作用

visual-studio - Visual Studio 2008 不必要的项目构建

Xcode - 自动将文件夹中的所有文件添加到目标

c# - 通过命令行构建 Visual Studio 项目

java - 在 Eclipse 中使用 Ant 时出现错误运行 javac.exe 编译器消息