Bird
Raised Fist0
Dockerdevops~20 mins

Tagging images during build in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Docker Tagging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Docker build command?
You run the command docker build -t myapp:1.0 . in a directory with a valid Dockerfile. What will be the tag of the built image?
Docker
docker build -t myapp:1.0 .
AThe image will be tagged as 'myapp:latest'.
BThe image will be tagged as 'latest'.
CThe image will be tagged as 'myapp:1.0'.
DThe image will have no tag.
Attempts:
2 left
💡 Hint
The -t option sets the tag explicitly.
❓ Configuration
intermediate
1:30remaining
Which Dockerfile instruction sets the image tag during build?
You want to set the image tag inside the Dockerfile itself during build time. Which instruction achieves this?
ALABEL version="1.0"
BThere is no Dockerfile instruction to set the image tag; tags are set during the docker build command.
CENV TAG=1.0
DTAG myapp:1.0
Attempts:
2 left
💡 Hint
Think about where tags are applied in Docker workflow.
🔀 Workflow
advanced
2:00remaining
How to tag the same image with multiple tags during build?
You want to build a Docker image and tag it as both 'myapp:1.0' and 'myapp:latest' in one command. Which command achieves this?
Adocker build -t myapp:1.0,latest .
Bdocker build -tag myapp:1.0 -tag myapp:latest .
Cdocker build --tag myapp:1.0 --tag myapp:latest .
Ddocker build -t myapp:1.0 -t myapp:latest .
Attempts:
2 left
💡 Hint
Multiple -t options can be used.
❓ Troubleshoot
advanced
2:00remaining
Why does this Docker build command fail to tag the image?
You run docker build . -t myapp:1.0 but the image is not tagged as expected. What is the problem?
Docker
docker build . -t myapp:1.0
AThe -t option must come before the build context '.'
BThe tag 'myapp:1.0' is invalid
CDockerfile is missing in the directory
DThe build context '.' is incorrect
Attempts:
2 left
💡 Hint
Check the order of options and arguments in the command.
✅ Best Practice
expert
2:30remaining
What is the best practice for tagging images in CI/CD pipelines?
In a CI/CD pipeline, you want to tag Docker images to track builds uniquely and also have a stable tag for deployment. Which tagging strategy is best?
ATag images with the commit SHA and also tag the same image as 'latest' for deployment
BOnly tag images as 'latest' to keep it simple
CTag images with random numbers to avoid collisions
DTag images with timestamps only
Attempts:
2 left
💡 Hint
Consider traceability and stable references.

Practice

(1/5)
1. What is the purpose of using the -t option in the docker build command?
easy
A. To assign a name and tag to the image during build
B. To specify the Dockerfile location
C. To run the container after building the image
D. To remove intermediate containers after build

Solution

  1. Step 1: Understand the docker build command options

    The -t option is used to tag the image with a name and optionally a tag.
  2. Step 2: Identify the purpose of tagging

    Tagging helps to identify and manage images easily by giving them a readable name and version.
  3. Final Answer:

    To assign a name and tag to the image during build -> Option A
  4. Quick Check:

    -t tags image [OK]
Hint: Remember: -t means tag your image name during build [OK]
Common Mistakes:
  • Confusing -t with specifying Dockerfile path
  • Thinking -t runs the container
  • Assuming -t deletes containers
2. Which of the following is the correct syntax to build a Docker image named myapp with tag v1 from the current directory?
easy
A. docker build -t myapp:v1 .
B. docker build myapp:v1 .
C. docker build -name myapp:v1 .
D. docker build --tag=myapp v1 .

Solution

  1. Step 1: Recall the correct docker build syntax for tagging

    The correct syntax uses -t name:tag followed by the build context (here, .).
  2. Step 2: Match the options with correct syntax

    docker build -t myapp:v1 . matches the correct syntax: docker build -t myapp:v1 .
  3. Final Answer:

    docker build -t myapp:v1 . -> Option A
  4. Quick Check:

    docker build -t name:tag . [OK]
Hint: Use -t before name:tag and end with build context [OK]
Common Mistakes:
  • Omitting -t option
  • Using incorrect flags like -name
  • Placing tag after context
3. What will be the output of the command docker images after running docker build -t testapp:latest . successfully?
medium
A. An error message about missing tag
B. No new images listed
C. A container named testapp running
D. An image named testapp with tag latest listed

Solution

  1. Step 1: Understand what docker build -t testapp:latest . does

    This command builds an image and tags it as testapp:latest.
  2. Step 2: Check what docker images shows

    The docker images command lists all images including the newly built one with its name and tag.
  3. Final Answer:

    An image named testapp with tag latest listed -> Option D
  4. Quick Check:

    Build tags appear in docker images [OK]
Hint: Built images show up with their tags in docker images list [OK]
Common Mistakes:
  • Expecting containers to appear in images list
  • Thinking build fails without explicit tag
  • Confusing image and container outputs
4. You run docker build -t myimage: . but get an error saying "invalid reference format". What is the most likely cause?
medium
A. The build context path is incorrect
B. The Dockerfile is missing in the directory
C. The tag name is missing a tag part after colon
D. The image name contains uppercase letters

Solution

  1. Step 1: Analyze the error message "invalid reference format"

    This error usually means the image name or tag format is wrong.
  2. Step 2: Check the command docker build -t myimage: .

    myimage: has a colon but no tag after it, causing the "invalid reference format" error.
  3. Step 3: Identify the most common cause

    The most common cause is a missing tag after colon in the tag name, causing invalid format.
  4. Final Answer:

    The tag name is missing a tag part after colon -> Option C
  5. Quick Check:

    Tag must be after colon, else invalid format error [OK]
Hint: Check for colon without tag in image name [OK]
Common Mistakes:
  • Assuming missing Dockerfile causes this error
  • Confusing build context errors with tag format
  • Thinking uppercase letters cause invalid format
5. You want to build a Docker image from a Dockerfile in ./app directory and tag it with two tags: myapp:1.0 and myapp:latest. Which command correctly does this in one build?
hard
A. docker build -t myapp:1.0 ./app && docker tag myapp:1.0 myapp:latest
B. docker build -t myapp:1.0 -t myapp:latest ./app
C. docker build --tag myapp:1.0 ./app && docker build --tag myapp:latest ./app
D. docker build -t myapp:1.0:latest ./app

Solution

  1. Step 1: Understand how to tag multiple tags in one build

    Docker allows multiple -t options in one build command to assign multiple tags.
  2. Step 2: Analyze the options

    docker build -t myapp:1.0 -t myapp:latest ./app uses two -t flags in one command, which is correct. docker build -t myapp:1.0 ./app && docker tag myapp:1.0 myapp:latest uses two commands, which works but is two steps, not one. docker build --tag myapp:1.0 ./app && docker build --tag myapp:latest ./app runs two builds, inefficient. docker build -t myapp:1.0:latest ./app uses invalid tag format.
  3. Final Answer:

    docker build -t myapp:1.0 -t myapp:latest ./app -> Option B
  4. Quick Check:

    Use multiple -t flags to tag once [OK]
Hint: Use multiple -t flags in one build command [OK]
Common Mistakes:
  • Trying to combine tags with colon in one string
  • Running multiple builds instead of tagging once
  • Using incorrect flag names like --tag
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