How to test dockerignore file?

2019-02-05 18:25发布

After reading the .dockerignore documentation, I'm wondering if there is a way to test it?

Examples

**/node_modules/

How do I check my dockerfile ignore the correct files and directories?

3条回答
放我归山
2楼-- · 2019-02-05 18:46

One way is to make a small Dockerfile with an ADD or COPY directive in it.

Try to add or copy a file in a node_modules folder: it is does not succeed, that would be because of the .dockerignore.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-05 18:54

To get a detailed analysis of the build context you could use pwaller/docker-show-context.

$ go get -v -u github.com/pwaller/docker-show-context
$ cd ~/path/to/project/using/docker
$ docker-show-context

It outputs statistics about the build such as file sizes and upload times.

查看更多
▲ chillily
4楼-- · 2019-02-05 18:59

To expand on VonC's suggestion, here's a sample Dockerfile and set of build/run commands you can use to create a container with the current folder's build context (named Dockerfile.build-context to avoid conflicting with your project's Dockerfile):

FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .

Once created, execute these commands in the command line:

docker build -f Dockerfile.build-context -t build-context .
docker run --rm -it build-context

When you copy/paste the above to a prompt, the run command will output the files that were copied to the Docker host that are not ignored by your .dockerignore file.

查看更多
登录 后发表回答