Docker

Lesson 01

Build context and .dockerignore

Keep the Docker build context small and intentional so builds are faster, safer, and easier to reproduce.

Good Code

.dockerignore
node_modules
.git
.env
.next
coverage
dist
*.log
Dockerfile*
compose*.yaml

Bad Code

.dockerignore
# Everything in the repository is sent to the builder.

Review Notes

What to review

Good Code

The good version excludes dependency folders, local build output, secrets, logs, and repository metadata from the build context.

Bad Code

The bad version sends the whole repository to the builder. That makes cache invalidation noisy and increases the chance of copying sensitive or irrelevant files.

Takeaways

  • The build context is part of the input to your image, so review what files are allowed into it.