Challenge - 5 Problems
Volume Mastery in Compose
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Volume Mount Behavior in Docker Compose
Given the following
docker-compose.yml snippet, what will be the output of docker volume ls after running docker-compose up -d?Docker
version: '3.8'
services:
app:
image: busybox
volumes:
- data-volume:/data
volumes:
data-volume:Attempts:
2 left
💡 Hint
Docker Compose prefixes volume names with the project directory name by default.
✗ Incorrect
Docker Compose creates volumes with the project name prefix by default. So the volume named 'data-volume' in the compose file becomes 'project_data-volume' in Docker volume list.
❓ Configuration
intermediate2:00remaining
Correct Volume Syntax in Compose
Which option correctly defines a named volume and mounts it to
/var/lib/data inside the container in a docker-compose.yml file?Attempts:
2 left
💡 Hint
Named volumes are declared under top-level volumes and referenced by name in services.
✗ Incorrect
Option D correctly declares a named volume 'mydata' and mounts it to '/var/lib/data' inside the container. The volume is declared under top-level volumes without empty config, which is valid.
❓ Troubleshoot
advanced2:00remaining
Volume Mount Not Persisting Data
You have this
docker-compose.yml:
version: '3.8'
services:
db:
image: postgres
volumes:
- ./dbdata:/var/lib/postgresql/data
After restarting the container, your data is lost. What is the most likely cause?Attempts:
2 left
💡 Hint
Bind mounts use host directories which can overwrite container data if empty.
✗ Incorrect
Using a bind mount to an empty host directory overwrites the container's data directory, causing data loss on restart.
🔀 Workflow
advanced2:00remaining
Volume Sharing Between Services
You want two services in your Compose file to share the same persistent data. Which volume configuration achieves this?
Docker
version: '3.8'
services:
service1:
image: alpine
volumes:
- shared-data:/data
service2:
image: alpine
volumes:
- shared-data:/data
volumes:
shared-data:Attempts:
2 left
💡 Hint
Named volumes can be shared by multiple services by referencing the same volume name.
✗ Incorrect
Mounting the same named volume 'shared-data' in both services allows them to share persistent data at '/data'.
✅ Best Practice
expert2:00remaining
Best Practice for Volume Declaration in Compose
Which option follows the best practice for declaring and using volumes in a Docker Compose file for production environments?
Attempts:
2 left
💡 Hint
Named volumes managed by Docker provide better portability and data safety than bind mounts.
✗ Incorrect
Best practice is to declare named volumes under top-level volumes and mount them in services to ensure data persistence and portability.