0
0
Dockerdevops~20 mins

Building images with docker build - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Build Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Docker build command?
You run the command docker build -t myapp:latest . in a directory with a valid Dockerfile. What will be the result?
ADocker will build the image but tag it as 'latest' without the 'myapp' name.
BDocker builds the image and tags it as 'myapp:latest' if successful.
CDocker builds the image but does not tag it because the '-t' flag is ignored.
DDocker will throw an error because the tag format is incorrect.
Attempts:
2 left
💡 Hint
The '-t' flag is used to name and tag the image during build.
💻 Command Output
intermediate
2:00remaining
What error does this Docker build command produce?
You run docker build -f Dockerfile.dev . but the file 'Dockerfile.dev' does not exist in the directory. What error will Docker show?
APermission denied error accessing Dockerfile.dev
BSyntax error in Dockerfile.dev
CBuild completes successfully using default Dockerfile
DError response from daemon: Dockerfile not found: Dockerfile.dev
Attempts:
2 left
💡 Hint
The '-f' flag specifies a Dockerfile name. If missing, Docker uses 'Dockerfile'.
🔀 Workflow
advanced
2:00remaining
Which option correctly builds a Docker image using a specific Dockerfile and no cache?
You want to build an image named 'webapp:1.0' using the Dockerfile named 'Dockerfile.prod' and ensure no cache is used during build. Which command is correct?
Adocker build -t webapp:1.0 -f Dockerfile.prod --no-cache .
Bdocker build --no-cache -t webapp:1.0 Dockerfile.prod
Cdocker build -f Dockerfile.prod -t webapp:1.0 . --no-cache
Ddocker build -t webapp:1.0 . -f Dockerfile.prod --no-cache
Attempts:
2 left
💡 Hint
The order of flags matters; the context path must be last.
Troubleshoot
advanced
2:00remaining
Why does this Docker build command fail with a syntax error?
You run docker build -t myimage . -f Dockerfile and get a syntax error. What is the cause?
ADockerfile name is case sensitive and 'Dockerfile' is incorrect
BThe tag '-t' must be after the context path '.'
CThe '-f' flag must come before the context path '.'
DThe context path '.' must be omitted when using '-f'
Attempts:
2 left
💡 Hint
Flags must appear before the context path in the command.
Best Practice
expert
2:00remaining
What is the best practice to reduce image size when building with Docker?
You want to build a small Docker image for production. Which practice below helps reduce the final image size?
AUse multi-stage builds to copy only necessary artifacts into the final image
BUse the 'latest' tag to always get the newest base image
CInstall all build tools inside the final image for debugging
DAvoid specifying a base image to keep the image minimal
Attempts:
2 left
💡 Hint
Multi-stage builds separate build environment from runtime environment.