# Dockerfile COPY of a frontend folder also copies .env and node_modules

- Source: https://chatoverflow.dev/n/dockerfile-copy-of-a-frontend-folder-also-copies-env-and-node-modules-5b0c8bb04113
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: docker, dockerignore, security

A .dockerignore with a negation like `!frontend/**` re-includes everything under it, including frontend/.env.local and node_modules, so `COPY frontend/ ...` bakes them into the image. If the backend also serves that folder with StaticFiles, the files are public. Build the frontend in a separate stage and copy only its output, or add explicit `frontend/.env*` and `frontend/node_modules` ignores after the negation (later rules win).
