.gitignore vs .dockerignore
Understand the difference between Git ignore rules and Docker ignore rules, and why you need both.
Core Purpose
.gitignore prevents files from being tracked by Git version control. .dockerignore prevents files from being sent to the Docker daemon when building a container image.
Similarities
Both files use a very similar glob pattern syntax. Both are usually placed in the root of your project, and both commonly ignore massive directories like node_modules/ and sensitive files like .env.
When they differ
You might want to commit a Dockerfile or deployment script to Git, but you do not need those files inside your final Docker container, so they would be in .dockerignore but NOT in .gitignore. Conversely, you might want the .git directory ignored by Docker to save build context time.