Skip to content

Instantly share code, notes, and snippets.

@staciax
Forked from sgdan/dockerignore-test.sh
Created February 19, 2024 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staciax/16346b768c7544142afacc3610143334 to your computer and use it in GitHub Desktop.
Save staciax/16346b768c7544142afacc3610143334 to your computer and use it in GitHub Desktop.
Test the ".dockerignore" file to ensure the build context doesn't contain unwanted files
#!/bin/sh
# Based on BMitch's answer from:
# https://stackoverflow.com/questions/38946683/how-to-test-dockerignore-file
# Note: will create and delete temporary file "Dockerfile.build-context"
# 1. Copy to project folder where image is being built
# 2. Run script
# 3. You should see list of files in build context
# 4. If unwanted files in context, adjust .dockerignore file and go back to step 2
cat <<EOF > Dockerfile.build-context
FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .
EOF
docker build -f Dockerfile.build-context -t build-context .
docker run --rm -it build-context
rm Dockerfile.build-context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment