dockerdockerignore

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


I have a large monorepo that I'm using as a docker context. The src for the repo is only 250MB, but many of the sub-projects have .gitignored virtualenvs, npm_modules, etc.

It appears that one or many of these .gitignores didn't make it into .dockerignore, because I'm seeing 5GB of context being transmitted on my machine, which is both slow, and I want to debug what's missing from .dockerignore.

Is there a way to get a list of the files being sent as part of the docker context so I can debug what's in .gitignore that's missing from .dockerignore?


Solution

  • Not directly that I know of, but indirectly it wouldn't be that hard. You can COPY the entire build context into an image and then do whatever you want with that content.

    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