0
0
Dockerdevops~20 mins

docker-compose.yml structure - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Compose Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of docker-compose up with multiple services
Given this docker-compose.yml file, what will be the output when running docker-compose up?
Docker
version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  db:
    image: postgres:13
    environment:
      POSTGRES_PASSWORD: example
AStarts two containers: one running nginx accessible on port 8080, and one running postgres with password set
BStarts one container combining nginx and postgres in a single service
CFails with error: 'image not found' because alpine tag is invalid
DStarts only the nginx container; postgres is ignored
Attempts:
2 left
💡 Hint
Think about how docker-compose handles multiple services defined under 'services'.
Configuration
intermediate
2:00remaining
Correct syntax for environment variables in docker-compose.yml
Which option shows the correct way to set environment variables for a service in docker-compose.yml?
A
environment:
  - POSTGRES_PASSWORD: example
  - POSTGRES_USER: admin
B
environment:
  POSTGRES_PASSWORD: example
  POSTGRES_USER: admin
C
environment:
  POSTGRES_PASSWORD=example
  POSTGRES_USER=admin
D
environment:
  - POSTGRES_PASSWORD=example
  - POSTGRES_USER=admin
Attempts:
2 left
💡 Hint
Look for the YAML mapping style used for environment variables.
Troubleshoot
advanced
2:00remaining
Error caused by incorrect indentation in docker-compose.yml
What error will occur if the following docker-compose.yml snippet is used?
Docker
version: '3.8'
services:
  web:
  image: nginx:alpine
  ports:
    - "8080:80"
Adocker-compose fails with 'image not found' error
Bdocker-compose runs successfully with no errors
Cdocker-compose ignores the 'ports' section silently
Dyaml.parser.ParserError due to incorrect indentation under 'web'
Attempts:
2 left
💡 Hint
YAML is sensitive to spaces and indentation.
🔀 Workflow
advanced
3:00remaining
Order of steps to add a new service to an existing docker-compose.yml
What is the correct order of steps to add a new service called 'cache' running Redis to an existing docker-compose.yml and start it?
A1,4,2,3
B4,1,2,3
C1,2,4,3
D2,1,4,3
Attempts:
2 left
💡 Hint
Think about editing the file before starting services and verifying after.
Best Practice
expert
3:00remaining
Choosing the best way to share environment variables securely in docker-compose.yml
Which option is the best practice to securely provide environment variables like passwords to services in docker-compose.yml?
AHardcode passwords directly in the environment section of docker-compose.yml
BPass passwords as command line arguments when running docker-compose up
CUse an external .env file and reference variables in docker-compose.yml
DStore passwords in the image and do not specify in docker-compose.yml
Attempts:
2 left
💡 Hint
Think about separating secrets from code files.