ZEUS LAB
GUIDE

.gitignore does not protect docker build: check what your build context really sends.gitignore は docker build を守らない:ビルドが実際に何を送っているかを確かめる

Counts from 100 public AI and MCP repositories on .dockerignore coverage, a one-line check of what your own build context contains, and the lines to add.公開AI・MCPリポジトリ100件の .dockerignore の集計と、自分のビルド対象に何が入っているかを1行で確かめる方法、足す行。

What we counted数えた結果

On 2026-11-12 we looked at 100 active public AI and MCP repositories. 30 had a Dockerfile at the root; 28 of those had a .dockerignore; 18 of those 30 kept .env out of the build context and 21 kept .git out. For comparison, 76 of the 100 had an .env rule in .gitignore. A missing rule is not a leak: whether a file reaches an image depends on the COPY lines, which we did not read.2026-11-12 に、活動中の公開AI・MCPリポジトリ100件を見ました。直下に Dockerfile があったのは30件、そのうち .dockerignore があったのは28件。その30件のうち、.env をビルド対象から外していたのは18件、.git を外していたのは21件でした。比較として、.gitignore に .env の除外があったのは100件中76件です。記述が無いことは漏えいではありません。ファイルがイメージに入るかどうかは COPY の書き方しだいで、そこは読んでいません。

Why the two files are separateなぜ2つのファイルは別なのか

With a local folder as the build context, docker build makes that folder available to the builder, minus what .dockerignore excludes. Git's ignore rules play no part. A COPY . . then copies whatever is available, including a local .env that Git never saw.手元のフォルダをビルド対象にすると、docker build は、そのフォルダから .dockerignore で除いた残りを、ビルドする側が使えるようにします。Git の除外の設定は関係しません。COPY . . は、使えるものをそのまま写します。Git が一度も見ていない手元の .env も含めてです。

Check your own context in one command自分のビルド対象を、コマンド1つで確かめる

This builds a throwaway image whose only job is to list files with three common name patterns that reached the context. If it prints a path, that file is available to your builds. The test itself hands those files to the builder and leaves build cache behind, so clear it afterwards with docker builder prune. It checks names only, and only these three patterns.これは、ビルド対象に届いたファイルのうち、よくある3つの名前の型に合うものを一覧にするだけの、使い捨てのイメージを作ります。パスが出たら、そのファイルはビルドから使える状態です。この確認そのものがファイルをビルドする側に渡し、キャッシュを残すので、終わったら docker builder prune で消してください。見ているのは名前だけで、この3つの型だけです。

printf 'FROM busybox\nCOPY . /ctx\nRUN find /ctx -name ".env*" -o -name "*.pem" -o -name "settings.local.json"\n' \
  | docker build --no-cache --progress=plain -f - .

Lines to add足す行

Start from these and add what your project keeps locally. The **/ prefix makes a pattern apply in subfolders too.まずこの行から。プロジェクトが手元に置くものを足してください。先頭の **/ は、下の階層のフォルダにも効かせるための書き方です。

# .dockerignore
.git
**/.env
**/.env.*
**/.claude
**/*.pem
**/*.key

Questionsよくある質問

If .env is in .gitignore, can it still end up in an image?.env が .gitignore にあっても、イメージに入ることはありますか。

Yes, when the image is built on a machine where the file exists and a COPY line takes the folder. .dockerignore is what keeps it out of the build context.あります。そのファイルがある端末でビルドし、COPY がフォルダごと写す場合です。ビルド対象から外すのは .dockerignore です。

Does a multi-stage build remove it?マルチステージのビルドなら消えますか。

Only if the final stage does not copy it. Earlier stages still received it, and an intermediate image pushed or cached elsewhere still holds it.最終段が写さなければ、最終のイメージには入りません。ただし前の段には届いており、途中のイメージを push やキャッシュした場合は、そこに残ります。

How can I check on every push?push のたびに確かめるには。

The free GitHub Action reports supported leak patterns in the repository's text files in the job summary. It reports; it does not inspect images.無料の GitHub Action が、リポジトリのテキストファイルにある対応済みの型を、ジョブの要約に報告します。報告だけで、イメージの中は検査しません。

Next次に

The 100-repository count100件の集計 →GitHub Action v1.2.1GitHub Action v1.2.1 →Zero-Trace Ship Kit — $39Zero-Trace Ship Kit — $39 →All guidesガイド一覧

Written with AI assistance (Claude). The figures are measured or computed as named on the page. The commands are examples: read them and adapt them to your repository before running. Product links lead to our own paid kits.AI(Claude)の補助を使って書いています。数字は、ページに記したとおりの実測値か計算値です。コマンドは例です。実行の前に読み、自分のリポジトリに合わせて直してください。商品のリンク先は、当方の有料のキットです。

ZEUS LAB is an independent software verification and development studio. It is not affiliated with any payment processing company of a similar name, or with any other company or service.※ZEUS LAB は独立したソフトウェア検証・開発スタジオであり、同名の決済代行会社および他社サービスとは一切関係ありません。