-
-
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
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
#!/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