Skip to content

Instantly share code, notes, and snippets.

@Masa-Shin
Forked from sgdan/dockerignore-test.sh
Last active January 14, 2022 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Masa-Shin/a269942609bf2d73aa780ade5f8c4f85 to your computer and use it in GitHub Desktop.
Save Masa-Shin/a269942609bf2d73aa780ade5f8c4f85 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
# 1. .dockerignoreをチェックしたいプロジェクトに移動し、このファイルを配置します。
# 2. 実行結果を保存するファイルを指定して、これを実行します。例:'./dockerignore-test.sh file_list.txt'
# 3. 指定したファイルにコンテナ内のファイル一覧が保存されます。
if [ "$1" = "" ]; then
echo "Error: Please specify a file to save the result."
exit 1
fi
if [ ! -e Dockerfile.build-context ]; then
cat <<EOF > Dockerfile.build-context
FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .
EOF
else
echo "Error: File 'Dockerfile.build-context' already exists. please rename it and try agein."
exit 1
fi
docker build -f Dockerfile.build-context -t build-context .
docker run --rm -it build-context > $1
rm Dockerfile.build-context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment