.dockerignore loại file khỏi build context trước khi gửi cho Docker builder. Nó giúp build nhanh hơn, cache ổn định hơn và tránh đưa secrets, logs, node_modules local hoặc artifacts lớn vào context.
Nên ignore .git, local env files, test output, coverage, build artifacts không cần, dependency folder local và file backup. Nếu build context quá lớn, Dockerfile tốt vẫn có thể build chậm vì builder phải nhận quá nhiều dữ liệu.