Summary - Build
- Docker & Kubernetes course
- Beginner
- Lesson 30/82
- 5 min
Combine build, tag and .dockerignore to create an image.
Summary: build
In this group:
docker build -t name:tag [-f Dockerfile] contextproduces an image.- A tag is a pointer; fixed version tags are used in production.
- The context is sent to the daemon; files outside it can't be accessed.
- Layers are cached; everything after a changed layer is rebuilt. Rarely changing steps are written at the top.
.dockerignoreshrinks the context and keeps secret files out.
docker build --pull -t api:1.2.0 -t api:latest .
docker history api:1.2.0Practice Version and prepare to publish
Write three commands: build api:1.2.0 updating the base image; also give this image the name ali/api:1.2.0; show the layer history.
Starter code
# buraya yazSample solution
docker build --pull -t api:1.2.0 .
docker tag api:1.2.0 ali/api:1.2.0
docker history api:1.2.0Expected output
[+] Building 6.3s (10/10) FINISHED => naming to docker.io/library/api:1.2.0 done IMAGE CREATED CREATED BY SIZE 4f1e2d3c4b5a 2 seconds ago CMD ["python" "app.py"] 0B
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which Dockerfile order uses the cache best?
- Source code → FROM → install
- The order doesn't matter
- FROM → dependency file → install → source code Correct answer
- FROM → source code → install
Explanation: The most frequently changing step is written last.
2 Build the image with a tag.
docker build ____ api:1.2.0 .
docker build -t api:1.2.0 .
Explanation: -t (tag) gives name:tag.
3 Match.
| Term | Meaning |
|---|---|
docker build |
Produces an image |
.dockerignore |
Context filter |
--no-cache |
Build without cache |
docker tag |
Extra name |