如何在获得意外大的 docker 构建上下文时让文件不被 .docker 忽略?

How to get files not being .dockerignored when getting an unexpectedly large docker build context?

我有一个大型 monorepo,用作 docker 上下文。 repo 的 src 只有 250MB,但是很多子项目都有 .gitignored virtualenvs,npm_modules,等等

似乎其中一个或多个 .gitignores 没有进入 .dockerignore,因为我看到我的机器上正在传输 5GB 的上下文,这既慢又我想要调试 .dockerignore.

中缺少的内容

有没有办法获取作为 docker 上下文的一部分发送的文件列表,以便我可以调试 .dockerignore 中缺少的 .gitignore 中的内容?

据我所知,不是直接的,但间接的,它不会那么难。您可以 COPY 将整个构建上下文放入图像中,然后使用该内容做任何您想做的事情。

FROM busybox
WORKDIR /stuff
# Just copy everything to the image
COPY . .
# Some default CMD is usually a good idea
CMD du -m | sort -n
# Build and run the image
docker build -t where-is-my-space -f Dockerfile.debug .
# The default `CMD` lists directories in the copied content
# sorted by size
docker run --rm where-is-my-space

# Huh, let's dig in more
docker run --rm where-is-my-space ls -l data/unexpected
# Or with an interactive shell (note, busybox doesn't have bash)
docker run --rm -it where-is-my-space sh

# All done, let's clean up
docker rmi where-is-my-space