Challenge - 5 Problems
Docker Compose Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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
Attempts:
2 left
💡 Hint
Think about how docker-compose handles multiple services defined under 'services'.
✗ Incorrect
docker-compose starts each service as a separate container. The 'web' service runs nginx on port 8080, and the 'db' service runs postgres with the specified environment variable.
❓ Configuration
intermediate2: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?Attempts:
2 left
💡 Hint
Look for the YAML mapping style used for environment variables.
✗ Incorrect
In docker-compose.yml, environment variables can be set as a mapping (key: value) or as a list of strings with key=value. Option B uses mapping correctly.
❓ Troubleshoot
advanced2: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"
Attempts:
2 left
💡 Hint
YAML is sensitive to spaces and indentation.
✗ Incorrect
The 'image' and 'ports' keys must be indented under 'web'. Incorrect indentation causes a YAML parsing error.
🔀 Workflow
advanced3: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?Attempts:
2 left
💡 Hint
Think about editing the file before starting services and verifying after.
✗ Incorrect
First add the service, then add ports if needed, then start services, then verify running containers.
✅ Best Practice
expert3: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?Attempts:
2 left
💡 Hint
Think about separating secrets from code files.
✗ Incorrect
Using an external .env file keeps secrets out of the main compose file and allows better security and flexibility.