0
0
Dockerdevops~20 mins

Building images in Compose in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Compose Build Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of docker-compose build with context path
Given this docker-compose.yml snippet, what will be the output when running docker-compose build?
Docker
services:
  web:
    build:
      context: ./app
      dockerfile: Dockerfile.web
    image: mywebapp:latest
ASuccessfully built image 'mywebapp:latest' using Dockerfile.web from ./app directory
BError: Cannot find Dockerfile in the root directory
CBuild completed but image tagged as 'latest' without 'mywebapp' prefix
DBuild fails due to missing context path
Attempts:
2 left
💡 Hint
The build context and dockerfile path determine where Docker looks for files.
Configuration
intermediate
2:00remaining
Correct syntax for build args in Compose
Which docker-compose.yml snippet correctly passes build arguments to the Docker build process?
A
build:
  context: .
  args:
    APP_ENV: production
    DEBUG: 'false'
B
build:
  context: .
  build_args:
    APP_ENV: production
    DEBUG: 'false'
C
build:
  context: .
  args:
    - APP_ENV=production
    - DEBUG=false
D
build:
  context: .
  build-args:
    APP_ENV: production
    DEBUG: 'false'
Attempts:
2 left
💡 Hint
Check the official Compose syntax for build arguments.
Troubleshoot
advanced
2:00remaining
Diagnosing build failure due to missing Dockerfile
You run docker-compose build but get the error: "Cannot locate specified Dockerfile: Dockerfile.prod". Your docker-compose.yml contains:
services:
  api:
    build:
      context: ./backend
      dockerfile: Dockerfile.prod

What is the most likely cause?
AThe dockerfile key must be an absolute path, not relative
BThe context path ./backend is incorrect and should be ./api
CDockerfile.prod does not exist inside the ./backend directory
DDocker Compose requires the Dockerfile to be named exactly 'Dockerfile'
Attempts:
2 left
💡 Hint
Check the location of the Dockerfile relative to the context.
🔀 Workflow
advanced
2:00remaining
Order of steps in multi-stage build with Compose
In a multi-stage Docker build defined in a Dockerfile, which step happens first when running docker-compose build?
ADocker builds only the stages referenced by the final image
BOnly the final stage is built, skipping earlier stages
CDocker builds all stages in parallel
DAll stages are built sequentially from the first to the last stage
Attempts:
2 left
💡 Hint
Think about how Docker processes multi-stage builds.
Best Practice
expert
2:00remaining
Optimizing build cache usage in Compose builds
Which practice best helps Docker Compose reuse build cache effectively when building images?
AUse COPY commands with wildcards to include all files in one step
BKeep the build context minimal and avoid changing files unnecessarily
CAdd a random build argument to force cache invalidation each time
DAlways use the latest tag for base images to get fresh builds
Attempts:
2 left
💡 Hint
Think about what invalidates Docker cache during build.