当您运行 docker build 时,Docker 将构建上下文(构建目录中的文件)发送到 daemon。.dockerignore 文件从此上下文中排除不需要的文件——加速构建、减小镜像大小并避免泄露敏感文件。
构建上下文
docker build -t myapp . # the "." is the build context — the directory sent to the daemon
# → Docker tarballs the ENTIRE context directory and sends it to the daemon BEFORE building
