0
0
Dockerdevops~10 mins

Image tags and versioning in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Image tags and versioning
Start with base image
Build image locally
Tag image with version or tag
Push image to registry
Pull image using tag
Run container from tagged image
Update image -> new tag
Repeat push and pull with new tag
This flow shows how Docker images are built, tagged with versions, pushed to a registry, and pulled for use. Tagging helps track different versions.
Execution Sample
Docker
docker build -t myapp:1.0 .
docker push myapp:1.0
docker pull myapp:1.0
docker run myapp:1.0
Builds an image tagged '1.0', pushes it, pulls it, and runs a container from it.
Process Table
StepCommandActionImage TagResult
1docker build -t myapp:1.0 .Build image locallymyapp:1.0Image created with tag 1.0
2docker push myapp:1.0Push image to registrymyapp:1.0Image myapp:1.0 uploaded
3docker pull myapp:1.0Pull image from registrymyapp:1.0Image myapp:1.0 downloaded
4docker run myapp:1.0Run container from imagemyapp:1.0Container started from myapp:1.0
5docker build -t myapp:2.0 .Build updated imagemyapp:2.0Image created with tag 2.0
6docker push myapp:2.0Push updated imagemyapp:2.0Image myapp:2.0 uploaded
7docker pull myapp:2.0Pull updated imagemyapp:2.0Image myapp:2.0 downloaded
8docker run myapp:2.0Run container from updated imagemyapp:2.0Container started from myapp:2.0
9Execution stops after running updated image
💡 No more commands; images built, tagged, pushed, pulled, and run with versions 1.0 and 2.0
Status Tracker
VariableStartAfter Step 1After Step 5Final
Image Tagsnonemyapp:1.0myapp:1.0, myapp:2.0myapp:1.0, myapp:2.0
Registry Stateemptymyapp:1.0 uploadedmyapp:1.0, myapp:2.0 uploadedmyapp:1.0, myapp:2.0 uploaded
Local Imagesemptymyapp:1.0 presentmyapp:1.0, myapp:2.0 presentmyapp:1.0, myapp:2.0 present
Running Containersnonerunning from myapp:1.0running from myapp:1.0 and myapp:2.0running from myapp:1.0 and myapp:2.0
Key Moments - 3 Insights
Why do we need to tag images with versions like '1.0' or '2.0'?
Tagging images lets us keep track of different versions. Without tags, Docker uses 'latest' by default, which can cause confusion about which version is running. See execution_table steps 1 and 5 where different tags are created.
What happens if we push an image without a tag?
Docker assigns the 'latest' tag automatically. This can overwrite previous 'latest' images and cause unexpected updates. In our example, explicit tags avoid this problem (execution_table steps 2 and 6).
Can we run a container from an image tag that does not exist locally?
Yes, Docker will try to pull the image from the registry first. In step 3 and 7, pulling happens before running to ensure the image is available.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table at step 4. What image tag is used to run the container?
Amyapp:1.0
Bmyapp:2.0
Clatest
Dmyapp:latest
💡 Hint
Check the 'Image Tag' column at step 4 in the execution_table.
At which step is the updated image with tag '2.0' first created?
AStep 2
BStep 6
CStep 5
DStep 8
💡 Hint
Look for 'Build updated image' action in the execution_table.
If we skip tagging the image during build, what tag will Docker assign by default?
Anone
Blatest
C1.0
Ddefault
💡 Hint
Refer to key_moments about default tags when no tag is specified.
Concept Snapshot
Docker images are tagged to identify versions.
Use 'docker build -t name:tag .' to create tagged images.
Push images with 'docker push name:tag' to share.
Pull images with 'docker pull name:tag' before running.
Tags prevent confusion and allow version control.
'latest' is default tag if none specified.
Full Transcript
This lesson shows how Docker images are built, tagged with versions like '1.0' or '2.0', pushed to a registry, pulled back, and run as containers. Tagging images helps track different versions and avoid confusion. The execution table traces commands step-by-step: building images with tags, pushing them to a registry, pulling them, and running containers from those tags. Variables track image tags, registry state, local images, and running containers. Key moments clarify why tagging is important, what happens if no tag is given, and how Docker pulls images if not found locally. The quiz tests understanding of tags used at each step and default behaviors. The snapshot summarizes the key commands and concepts for quick reference.