0

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

这些 .gitignore 中的一个或多个似乎没有进入 .dockerignore,因为我看到我的机器上正在传输 5GB 的上下文,这既慢又慢,我想调试 .dockerignore 中缺少的内容。

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

4

1 回答 1

1

不是直接的,我知道,但间接地它不会那么难。您可以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
于 2022-01-30T00:48:51.137 回答