How to test dockerignore file?

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?

  • How to change resolv.conf for existing docker containers
  • Using Docker to launch web app, can't connect to Postgresql DB?
  • Set execution timeout limit while creating docker
  • Docker-compose: ERR_EMPTY_RESPONSE
  • How can I add the used base (FROM) image to a docker image
  • Will docker cost system resources to exchange data with system?
  • How to enable docker remote API in “Docker for Windows”
  • Access Token for Dockerhub
  • CircleCI : configuring the test of Docker container hosted on gcp
  • Why can bash $() set environment variables?
  • Saving files on Mac OSX host to Docker container (auto-reloading)
  • Script run inside docker container reporting significantly higher memory than outside
  • 3 Solutions collect form web for “How to test dockerignore file?”

    To expand on VonC’s suggestion, here’s a sample dockerfile and build/run commands you can use to create a container with the current folders build context:

    $ cat >df.build-context <<EOF
    FROM busybox
    COPY . /build-context
    WORKDIR /build-context
    CMD find .
    EOF
    

    Then

    docker build -f df.build-context -t my-build-context .
    docker run --rm -it my-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 and not ignored by your .dockerignore file.

    Note: that the change in name for the Dockerfile is to avoid overwriting your existing project’s Dockerfile.

    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.

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.