docker build Explained
What docker build does, with an example.
Published November 7, 2026
docker build creates an image from a Dockerfile and a build context (the files in the folder). The result is tagged so you can run or push it.
How it works
Each Dockerfile instruction becomes a cached layer. Order instructions from least to most frequently changing to speed up rebuilds.
A .dockerignore file keeps unnecessary files out of the context.
Try it
docker build -t myapp:1.0 .
[+] Building 12.3s (8/8) FINISHED
=> exporting to image
docker images myapp
Practical examples
Build and tag
docker build -t myapp:1.0 .Another Dockerfile
docker build -f Dockerfile.prod -t myapp:prod .Build argument
docker build --build-arg NODE_VERSION=20 -t myapp .No cache
docker build --no-cache -t myapp .Common mistakes
- Huge build context because of a missing .dockerignore.
- COPY . . before dependency install, breaking the cache.
- Secrets baked into layers.
Key takeaways
- docker build creates an image from a Dockerfile and a build context (the files in the folder).
- Run docker <command> --help for all options.
- Clean up unused resources regularly.
FAQ
What is the dot?
The build context directory.
Where can I see all options?
Run the command with --help.