0
0
Dockerdevops~20 mins

Creating and managing volumes in Docker - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Volume Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
πŸ’» Command Output
intermediate
1:30remaining
Volume Creation Command Output
What is the output of the command docker volume create mydata when run on a system with no existing volume named mydata?
Docker
docker volume create mydata
AError: volume mydata already exists
BCreated volume with ID abc123
Cmydata
DNo output
Attempts:
2 left
πŸ’‘ Hint
The command returns the name of the created volume if successful.
❓ Troubleshoot
intermediate
1:30remaining
Volume Removal Error Diagnosis
You run docker volume rm mydata but get the error: Error: volume is in use - [container_id]. What is the most likely cause?
AThe volume is currently attached to a running container.
BThe volume does not exist on the system.
CDocker daemon is not running.
DThe volume is corrupted and cannot be removed.
Attempts:
2 left
πŸ’‘ Hint
Volumes cannot be removed if they are used by containers.
❓ Configuration
advanced
2:00remaining
Docker Compose Volume Configuration
In a docker-compose.yml file, which volume configuration correctly mounts a named volume dbdata to /var/lib/mysql inside the container?
Docker
version: '3.8'
services:
  db:
    image: mysql
    volumes:
A- dbdata:/var/lib/mysql
B- /var/lib/mysql:dbdata
C
- type: bind
  source: dbdata
  target: /var/lib/mysql
D
- type: volume
  source: dbdata
  target: /var/lib/mysql
Attempts:
2 left
πŸ’‘ Hint
Use the long syntax for named volumes with type volume.
πŸ”€ Workflow
advanced
2:30remaining
Volume Backup and Restore Workflow
Which sequence of commands correctly backs up a Docker volume named mydata to a tar file and then restores it?
Adocker volume export mydata > mydata.tar.gz && docker volume import mydata.tar.gz mydata
Bdocker run --rm -v mydata:/data -v $(pwd):/backup busybox tar czf /backup/mydata.tar.gz /data && docker run --rm -v mydata:/data -v $(pwd):/backup busybox tar xzf /backup/mydata.tar.gz -C /data
Cdocker cp mydata:/ /backup/mydata.tar.gz && docker cp /backup/mydata.tar.gz mydata:/
Ddocker save mydata > mydata.tar.gz && docker load mydata.tar.gz
Attempts:
2 left
πŸ’‘ Hint
Use a temporary container to access volume data for backup and restore.
βœ… Best Practice
expert
2:00remaining
Choosing Volume Types for Persistent Data
Which statement best describes when to use Docker named volumes instead of bind mounts for persistent data?
AUse named volumes when you want Docker to manage the storage location and lifecycle of data independently from the host filesystem.
BUse named volumes only when you need to share data between containers on different hosts.
CUse bind mounts when you want Docker to manage data storage automatically without host interference.
DUse bind mounts to store data inside Docker’s internal volume storage area.
Attempts:
2 left
πŸ’‘ Hint
Think about who controls the data location and lifecycle.