Bird
Raised Fist0
Dockerdevops~5 mins

Image tags and versioning in Docker - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you build and share Docker images, you need a way to identify different versions clearly. Image tags let you label images with names and versions so you know exactly which one you are using or sharing.
When you want to run a specific version of an application in a container.
When you need to update your app but keep the old version available for rollback.
When you share images with your team or publish them to a registry like Docker Hub.
When you automate deployments and want to control which image version is deployed.
When you want to avoid using the default 'latest' tag to prevent unexpected updates.
Commands
Builds a Docker image from the current folder and tags it as 'my-app' with version '1.0'. This helps identify this specific build.
Terminal
docker build -t my-app:1.0 .
Expected OutputExpected
Sending build context to Docker daemon 2.048kB Step 1/3 : FROM alpine ---> a24bb4013296 Step 2/3 : RUN echo Hello World ---> Running in 3c1f2b7d9f3a Removing intermediate container 3c1f2b7d9f3a ---> 5d8b7f3a7c1e Step 3/3 : CMD ["echo", "Hello World"] ---> Running in 9f8a7b6c5d4e Removing intermediate container 9f8a7b6c5d4e ---> 7f9d3a2b1c0e Successfully built 7f9d3a2b1c0e Successfully tagged my-app:1.0
→
-t - Assigns a name and tag to the image
Lists all images named 'my-app' with their tags and IDs so you can see the versions available locally.
Terminal
docker images my-app
Expected OutputExpected
REPOSITORY TAG IMAGE ID CREATED SIZE my-app 1.0 7f9d3a2b1c0e 10 seconds ago 5MB
Tags the existing 'my-app:1.0' image also as 'my-app:latest' so it can be referenced by the common 'latest' tag.
Terminal
docker tag my-app:1.0 my-app:latest
Expected OutputExpected
No output (command runs silently)
Uploads the 'my-app:1.0' image to the Docker registry so others can pull this exact version.
Terminal
docker push my-app:1.0
Expected OutputExpected
The push refers to repository [docker.io/library/my-app] 1.0: Pushed
Downloads the 'my-app:1.0' image from the registry to use it locally or in deployment.
Terminal
docker pull my-app:1.0
Expected OutputExpected
1.0: Pulling from library/my-app Digest: sha256:abcdef1234567890 Status: Downloaded newer image for my-app:1.0
Key Concept

If you remember nothing else from this pattern, remember: always tag your Docker images with meaningful version numbers to control which version you use or share.

Common Mistakes
Using the 'latest' tag without specifying a version.
This can cause unexpected updates because 'latest' always points to the newest image, which might break your app.
Always tag images with explicit version numbers like '1.0' and use those tags in your deployments.
Not tagging images before pushing to a registry.
Docker will push the image with the default 'latest' tag, which may not be what you want.
Tag your image with the correct version before pushing, e.g., 'docker tag my-app:1.0 my-app:stable' then push.
Summary
Build Docker images with tags to label versions clearly.
Use 'docker images' to list available image versions locally.
Tag images explicitly before pushing to share specific versions.
Pull images by tag to get the exact version you need.
Avoid relying on the 'latest' tag alone to prevent surprises.

Practice

(1/5)
1. What is the default tag used by Docker if no tag is specified when pulling an image?
easy
A. stable
B. 1.0
C. latest
D. default

Solution

  1. Step 1: Understand Docker image tagging

    Docker images can have tags to specify versions or variants.
  2. Step 2: Identify the default tag behavior

    If no tag is specified, Docker uses the tag named "latest" by default.
  3. Final Answer:

    latest -> Option C
  4. Quick Check:

    Default tag = latest [OK]
Hint: No tag means Docker uses 'latest' automatically [OK]
Common Mistakes:
  • Assuming 'stable' is default tag
  • Thinking '1.0' is default version
  • Believing 'default' is a valid tag
2. Which of the following is the correct syntax to pull a Docker image with a specific tag?
easy
A. docker pull ubuntu:20.04
B. docker pull ubuntu-20.04
C. docker pull ubuntu/20.04
D. docker pull ubuntu#20.04

Solution

  1. Step 1: Recall Docker image tag syntax

    The correct syntax to specify a tag is image_name:tag.
  2. Step 2: Match syntax with options

    Only docker pull ubuntu:20.04 uses a colon to separate image name and tag correctly.
  3. Final Answer:

    docker pull ubuntu:20.04 -> Option A
  4. Quick Check:

    Use colon ':' to specify tag [OK]
Hint: Use ':' between image name and tag [OK]
Common Mistakes:
  • Using dash '-' instead of colon ':'
  • Using slash '/' instead of colon
  • Using hash '#' instead of colon
3. Given the command docker pull nginx:1.21, what will be the result?
medium
A. Docker throws an error due to invalid tag
B. Docker pulls the latest nginx image ignoring 1.21
C. Docker pulls all nginx images
D. Docker pulls the nginx image tagged 1.21

Solution

  1. Step 1: Analyze the pull command with tag

    The command specifies the image name 'nginx' and tag '1.21'.
  2. Step 2: Understand Docker pull behavior

    Docker pulls the exact image version matching the tag '1.21'.
  3. Final Answer:

    Docker pulls the nginx image tagged 1.21 -> Option D
  4. Quick Check:

    Tag specifies exact image version [OK]
Hint: Tag pulls specific image version, not latest [OK]
Common Mistakes:
  • Assuming tag is ignored and latest is pulled
  • Expecting error for valid tag
  • Thinking all images are pulled
4. You run docker pull alpine and get an error that the image is not found. What is the most likely cause?
medium
A. You forgot to specify the tag, and 'latest' tag is missing
B. The image 'alpine' does not exist on Docker Hub
C. Docker requires a tag to pull any image
D. Your internet connection is down

Solution

  1. Step 1: Understand default tag behavior

    When no tag is specified, Docker tries to pull the 'latest' tag.
  2. Step 2: Identify cause of error

    If the 'latest' tag does not exist for 'alpine', Docker cannot find the image.
  3. Final Answer:

    You forgot to specify the tag, and 'latest' tag is missing -> Option A
  4. Quick Check:

    Missing 'latest' tag causes pull failure [OK]
Hint: Always specify tag if 'latest' is missing [OK]
Common Mistakes:
  • Assuming image does not exist at all
  • Thinking tag is always required
  • Blaming internet without checking tags
5. You want to deploy a Docker image but ensure you always use version 2.5.3, never the latest. Which command correctly pulls this specific version and avoids accidental updates?
hard
A. docker pull myapp:stable
B. docker pull myapp:2.5.3
C. docker pull myapp:latest
D. docker pull myapp

Solution

  1. Step 1: Understand version control with tags

    Using a specific tag like '2.5.3' ensures you get that exact version.
  2. Step 2: Compare options for safety

    docker pull myapp:2.5.3 pulls the exact version. Options B and C pull 'latest' which can change. docker pull myapp:stable depends on tag existence.
  3. Final Answer:

    docker pull myapp:2.5.3 -> Option B
  4. Quick Check:

    Explicit version tag prevents accidental updates [OK]
Hint: Always specify exact version tag to avoid surprises [OK]
Common Mistakes:
  • Using 'latest' tag and getting unexpected updates
  • Assuming 'stable' tag always exists
  • Not specifying any tag and risking version changes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard