A Docker volume is a storage area outside the container's writable layer. It lets containers save and share data persistently, even if the container stops or is deleted.
Click to reveal answer
beginner
How do you create a Docker volume named mydata?
Use the command: docker volume create mydata This creates a new volume called mydata that containers can use to store data.
Click to reveal answer
beginner
How do you attach a volume to a container?
Use the -v or --mount option when running a container. For example: docker run -v mydata:/app/data myimage This mounts the volume mydata inside the container at /app/data.
Click to reveal answer
beginner
How can you list all Docker volumes on your system?
Run the command: docker volume ls This shows all volumes available on your Docker host.
Click to reveal answer
intermediate
How do you remove a Docker volume named mydata?
Use the command: docker volume rm mydata This deletes the volume named mydata. Make sure no container is using it first.
Click to reveal answer
What happens to data in a Docker volume if the container using it is deleted?
AThe data remains safe in the volume.
BThe data is deleted with the container.
CThe data is copied to the host's home directory.
DThe data is moved to a new container automatically.
✗ Incorrect
Docker volumes store data outside the container's writable layer, so deleting a container does not delete the volume or its data.
Which command creates a new Docker volume named backup?
Adocker volume create backup
Bdocker create volume backup
Cdocker volume new backup
Ddocker volume add backup
✗ Incorrect
The correct syntax to create a volume is docker volume create [name].
How do you mount a volume named data to the path /var/lib/data inside a container?
Adocker run --volume /var/lib/data:data image
Bdocker run -v /var/lib/data:data image
Cdocker run -v data:/var/lib/data image
Ddocker run --mount data:/var/lib/data image
✗ Incorrect
The -v option uses the syntax volume_name:container_path.
Which command lists all Docker volumes?
Adocker volume list
Bdocker volume ls
Cdocker volumes
Ddocker list volumes
✗ Incorrect
The correct command to list volumes is docker volume ls.
What must you do before removing a Docker volume?
ARestart the Docker service.
BStop all running containers.
CBackup the volume to a file.
DEnsure no container is using the volume.
✗ Incorrect
You cannot remove a volume if it is currently used by any container.
Explain how to create a Docker volume and use it in a container.
Think about commands to create and run containers with volumes.
You got /3 concepts.
Describe how to list and remove Docker volumes safely.
Consider commands and safety steps before deleting volumes.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of Docker volumes?
easy
A. To manage network connections between containers
B. To speed up container startup time
C. To create new containers automatically
D. To store data outside of containers so it is not lost when containers stop
Solution
Step 1: Understand what volumes do
Volumes store data outside the container's writable layer, so data persists even if the container is removed.
Step 2: Compare options
Only To store data outside of containers so it is not lost when containers stop describes this purpose correctly. Other options describe unrelated features.
Final Answer:
To store data outside of containers so it is not lost when containers stop -> Option D
Quick Check:
Volumes keep data safe outside containers = A [OK]
Hint: Volumes keep data safe outside containers [OK]
Common Mistakes:
Confusing volumes with container networking
Thinking volumes speed up container start
Assuming volumes create containers
2. Which command correctly creates a Docker volume named mydata?
easy
A. docker volume new mydata
B. docker volume create mydata
C. docker create volume mydata
D. docker volume add mydata
Solution
Step 1: Recall Docker volume creation syntax
The correct command to create a volume is docker volume create [name].
Step 2: Match options to syntax
Only docker volume create mydata matches the correct syntax exactly.
Final Answer:
docker volume create mydata -> Option B
Quick Check:
Use 'docker volume create' = C [OK]
Hint: Use 'docker volume create' to make volumes [OK]
Common Mistakes:
Using wrong command order like 'docker create volume'
Using non-existent commands like 'docker volume new'
Confusing 'add' with 'create'
3. What is the output of the command docker volume ls after creating two volumes named vol1 and vol2?
medium
A. Lists volumes including vol1 and vol2
B. Lists all containers running
C. Shows detailed info about vol1 only
D. Deletes volumes vol1 and vol2
Solution
Step 1: Understand what 'docker volume ls' does
This command lists all Docker volumes available on the system.
Step 2: Interpret the scenario
After creating volumes vol1 and vol2, the command will list both volumes among others.
Final Answer:
Lists volumes including vol1 and vol2 -> Option A
Quick Check:
'docker volume ls' lists volumes = A [OK]
Hint: 'docker volume ls' shows all volumes [OK]
Common Mistakes:
Confusing volume list with container list
Expecting detailed info instead of list
Thinking it deletes volumes
4. You run docker volume rm myvolume but get an error saying the volume is in use. What should you do to fix this?
medium
A. Restart Docker daemon and try removing again
B. Rename the volume before removing it
C. Stop and remove containers using the volume, then remove the volume
D. Use docker volume create again to overwrite it
Solution
Step 1: Understand volume usage error
Docker prevents removing volumes that are still attached to running or stopped containers.
Step 2: Fix by stopping/removing containers
You must stop and remove containers using the volume before deleting the volume itself.
Final Answer:
Stop and remove containers using the volume, then remove the volume -> Option C
Quick Check:
Remove containers before volumes in use = D [OK]
Hint: Remove containers using volume before deleting volume [OK]
Common Mistakes:
Trying to rename volume to delete it
Recreating volume instead of removing
Restarting Docker daemon without stopping containers
5. You want to create a Docker container that uses a volume named appdata to persist data at /data inside the container. Which command correctly does this?
hard
A. docker run --mount source=appdata,target=/data myimage
B. docker run -v /appdata:/data myimage
C. docker run -v /data appdata myimage
D. docker run --volume /data:appdata myimage
Solution
Step 1: Understand volume mounting syntax
The recommended syntax for mounting a named volume is docker run --mount source=volume_name,target=container_path image. The shorthand -v volume_name:container_path also works, but paths starting with / indicate bind mounts from the host.
Step 2: Compare options
docker run -v /appdata:/data myimage performs a bind mount from the host directory /appdata, not the named volume appdata. docker run --mount source=appdata,target=/data myimage correctly mounts the named volume appdata. The other options (-v /data appdata and --volume /data:appdata) have invalid syntax or incorrect source/target order.
Final Answer:
docker run --mount source=appdata,target=/data myimage -> Option A
Quick Check:
Use --mount source=appdata,target=/data = B [OK]
Hint: Use --mount source=vol,target=path for clarity [OK]
Common Mistakes:
Mixing volume and container paths order
Using incorrect flags like --volume with wrong syntax
Confusing shorthand and long form options
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.