Skip to content

🔒 Exclude .env from Docker build context - #10

Open
luiscosio wants to merge 1 commit into
mainfrom
fix/dockerignore-env
Open

🔒 Exclude .env from Docker build context#10
luiscosio wants to merge 1 commit into
mainfrom
fix/dockerignore-env

Conversation

@luiscosio

Copy link
Copy Markdown

One-line defense-in-depth fix, independent of #9.

Dockerfile line 4 runs COPY . . in the builder stage, and Docker does not read .gitignore. This repo ships .env.example, so real .env files exist on dev machines; building with one present bakes it into builder-stage layers in the local build cache. The published image is unaffected (multi-stage: final stage copies only the compiled binary), but cache layers are exportable (--target builder, cache pushes), so the context should never contain it.

.dockerignore already excluded /certs — this adds /.env and /.env.* alongside it.

Verification: .dockerignore semantics only — the entry follows the existing file's root-anchored pattern style. CI builds from a clean checkout and never had a .env, so no remote image is affected.

The builder stage runs COPY . . and Docker does not read .gitignore,
so a real .env (this repo ships .env.example) lands in builder-stage
layers in the local build cache. The final image is unaffected
(multi-stage, binary-only), but cache layers are exportable and
--target builder images would carry the secret. /certs was already
excluded; .env now is too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant