When running docker compose build, you get an error. What is wrong?
medium
A. You must specify context instead of build.
B. The dockerfile key must be inside the build block, not at the same level.
C. The build key cannot be a string; it must be a dictionary.
D. Docker Compose does not support custom Dockerfile names.
Solution
Step 1: Check Compose syntax for build and dockerfile
The dockerfile key must be nested inside the build dictionary, not at the same level as build.
Step 2: Identify the error cause
Here, build is a string, and dockerfile is separate, causing Compose to fail parsing.
Final Answer:
The dockerfile key must be inside the build block, not at the same level. -> Option B
Quick Check:
dockerfile inside build block [OK]
Hint: Put dockerfile under build, not beside it [OK]
Common Mistakes:
Placing dockerfile outside build block
Using build as string with dockerfile key separately
Assuming dockerfile key is global
5. You want to build two services in Compose, frontend and backend, each with different Dockerfiles in the same directory ./app. How do you configure the build section for both services correctly?
hard
A. Use context: ./app for both, and specify different dockerfile names under each service's build.
B. Use different context paths for each service pointing to the same directory.
C. Use one service with build and the other with image only.
D. You cannot build two images from the same directory with different Dockerfiles.
Solution
Step 1: Understand build context and dockerfile usage
You can use the same context directory but specify different dockerfile names to build different images from the same folder.
Step 2: Check options for multiple services
Use context: ./app for both, and specify different dockerfile names under each service's build. correctly uses the same context with different Dockerfiles. Use different context paths for each service pointing to the same directory. is redundant, C limits building, and D is false.
Final Answer:
Use context: ./app for both, and specify different dockerfile names under each service's build. -> Option A
Quick Check:
Same context + different dockerfile names [OK]
Hint: Same folder, different dockerfile names per service [OK]
Common Mistakes:
Trying to use different contexts for same folder
Thinking multiple Dockerfiles in one folder is unsupported
Not specifying dockerfile key for each service
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.