Abbi Labs

2026-11-16 · Daily security tips

Is your .env baked into your Docker image?

Many AI-written Dockerfiles copy the whole project with COPY . . and no .dockerignore. That copies your .env file and .git folder into the image. Anyone who can pull it, from a public Docker Hub repo or a shared registry, can open them. Deleting the file in a later step doesn't help, because the earlier layer still holds it.

Check: run docker run --rm --entrypoint ls your-image -la /app (swap /app for your WORKDIR). If .env or .git is listed, it shipped. Also look for ENV lines in the Dockerfile with real secret values, since docker inspect shows them.

Fix: add .env*, .git and node_modules to .dockerignore. Pass secrets at runtime through your host's environment settings, rebuild, and rotate any key that was in an image you pushed.