Last active
October 4, 2023 17:03
-
-
Save AlexAtkinson/96aea872b0af1ee367b9f24055421eb0 to your computer and use it in GitHub Desktop.
Docker Build - .dockerignore Interactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
dir=$(mktemp -d) | |
cd $dir > /dev/null | |
export DOCKER_BUILDKIT=1 | |
echo -e "FROM node:20-alpine\nCOPY . tmp/" > Dockerfile_foo | |
cp Dockerfile_foo Dockerfile_bar | |
touch foo bar | |
echo "foo" > .dockerignore | |
echo "bar" > Dockerfile_bar.dockerignore | |
docker build -t foo -f Dockerfile_foo . | |
docker build -t bar -f Dockerfile_bar . | |
echo -- foo -- | |
docker run foo ls tmp | grep '^foo\|^bar' | |
echo -- bar -- | |
docker run bar ls tmp | grep '^foo\|^bar' | |
echo -e "\nTEST: Observe how docker build handles .dockerignore files with BUILDKIT." | |
echo -e "\nRESULT: Docker build uses the <Dockerfile>.dockerignore and ignores .dockerignore." | |
echo -e "\nWARN: Disabling BUILDKIT results in the <Dockerfile>.dockerignore file being ignored." | |
cd - > /dev/null | |
rm -rf $dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this comment for original.
BUILDKIT or not to BUILDKIT... Just be cautious around .dockerignore dependencies and how they're handled both in the CI and the developer workflows.