🚫 .git folder in Docker Image? No!
Docker sends entire folder to daemon. .dockerignore excludes unnecessary files. Faster builds, smaller images, less clutter.
📝 .dockerignore Example
# Git .git/ .gitignore # Node node_modules/ npm-debug.log # .NET bin/ obj/ *.user *.suo # Tests test/ __tests__/ coverage/ # Logs *.log logs/ # Environment .env .env.local .env.*.local # IDE .vscode/ .idea/ *.sln *.csproj.user # OS .DS_Store Thumbs.db # Build artifacts dist/ build/ out/
✅ Benefits
- Faster builds: Less data to send to Docker daemon
- Smaller images: Excluded files don’t end up in layers
- Security: Exclude .env, secrets, .git history
- Cleaner: No IDE files, no temp files in image
“Build context was 500MB (node_modules!). Added .dockerignore → 50MB. Build time dropped 80%. Always use .dockerignore.”
