A named volume is a storage area managed by Docker that can be shared between containers and persists data even if containers are removed.
Click to reveal answer
beginner
How do you create and use a named volume in a Docker container?
Use the docker volume create myvolume command to create it, then run a container with docker run -v myvolume:/path/in/container to mount it.
Click to reveal answer
intermediate
Why use named volumes instead of bind mounts for data sharing?
Named volumes are managed by Docker, provide better portability, and avoid permission issues that can happen with bind mounts on host directories.
Click to reveal answer
beginner
Can multiple containers share the same named volume simultaneously?
Yes, multiple containers can mount the same named volume at the same time to share data between them.
Click to reveal answer
beginner
What happens to a named volume when the container using it is deleted?
The named volume remains on the host system until explicitly removed, so data is preserved beyond the container's life.
Click to reveal answer
Which command creates a named volume in Docker?
Adocker volume new myvolume
Bdocker create volume myvolume
Cdocker volume create myvolume
Ddocker volume init myvolume
✗ Incorrect
The correct command to create a named volume is docker volume create myvolume.
How do you mount a named volume inside a container at /data?
Adocker run -volumes myvolume:/data myimage
Bdocker run -v myvolume:/data myimage
Cdocker run --volume myvolume /data myimage
Ddocker run -mount myvolume:/data myimage
✗ Incorrect
Use -v myvolume:/data to mount the named volume inside the container.
What is a key benefit of using named volumes over bind mounts?
AThey are managed by Docker and avoid host permission issues
BThey are faster than bind mounts
CThey automatically sync with cloud storage
DThey delete data when containers stop
✗ Incorrect
Named volumes are managed by Docker and avoid common permission problems with host directories.
If you delete a container, what happens to its named volume?
AThe volume remains until manually removed
BThe volume is deleted automatically
CThe volume is backed up to Docker Hub
DThe volume is converted to a bind mount
✗ Incorrect
Named volumes persist after container deletion until you remove them explicitly.
Can two containers share the same named volume at the same time?
AOnly if containers run on different hosts
BNo, volumes are exclusive to one container
COnly if volumes are read-only
DYes, they can share data through the volume
✗ Incorrect
Multiple containers can mount the same named volume simultaneously to share data.
Explain what a named volume is and why it is useful for sharing data between Docker containers.
Think about how data stays safe even if containers are removed.
You got /4 concepts.
Describe the steps to create a named volume and use it in a Docker container.
Start with creating the volume, then attach it when running a container.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using named volumes in Docker?
easy
A. To isolate network traffic between containers
B. To speed up container startup time
C. To share and persist data between containers safely
D. To limit CPU usage of containers
Solution
Step 1: Understand what named volumes do
Named volumes store data outside the container's writable layer, allowing data to persist beyond container life.
Step 2: Identify the main benefit
This persistence and sharing of data between containers is the key purpose of named volumes.
Final Answer:
To share and persist data between containers safely -> Option C
Quick Check:
Named volumes = data sharing and persistence [OK]
Hint: Named volumes keep data safe and share it [OK]
Common Mistakes:
Confusing volumes with network settings
Thinking volumes improve CPU or speed
Assuming volumes delete data with containers
2. Which of the following is the correct command to create a named volume called mydata?
easy
A. docker volume create mydata
B. docker create volume mydata
C. docker volume new mydata
D. docker volume make mydata
Solution
Step 1: Recall Docker volume creation syntax
The correct command to create a volume is docker volume create [name].
Step 2: Match the command with options
Only docker volume create mydata uses the correct syntax: docker volume create mydata.
Final Answer:
docker volume create mydata -> Option A
Quick Check:
Volume create command = docker volume create [OK]
Hint: Use 'docker volume create' to make named volumes [OK]
Common Mistakes:
Swapping order of words in the command
Using 'new' or 'make' instead of 'create'
Omitting the 'volume' keyword
3. Given the command:
docker run -d --name app1 -v myvol:/app/data busybox sleep 1000
What happens to the data inside /app/data if the container app1 is removed?
medium
A. Data inside /app/data is saved in the named volume 'myvol'
B. Data inside /app/data is lost unless backed up manually
C. Data inside /app/data is copied to the host's /var/lib/docker folder automatically
D. Data inside /app/data is deleted with the container
Solution
Step 1: Understand volume mounting in the command
The -v myvol:/app/data option mounts the named volume 'myvol' to the container path '/app/data'.
Step 2: Know volume persistence behavior
Named volumes keep data even if the container is removed, so data inside '/app/data' is saved in 'myvol'.
Final Answer:
Data inside /app/data is saved in the named volume 'myvol' -> Option A
Quick Check:
Named volume keeps data after container removal [OK]
Hint: Named volumes keep data safe after container removal [OK]
Common Mistakes:
Thinking data deletes with container
Confusing named volumes with anonymous volumes
Assuming data copies to host automatically
4. You run this command to share data between two containers:
docker run -d --name c1 -v sharedvol:/data busybox sleep 1000
docker run -d --name c2 -v sharedvol:/data busybox sleep 1000
But container c2 cannot see files created by c1 inside /data. What is the likely problem?
medium
A. The volume mount syntax is incorrect
B. Containers must be on the same network to share volumes
C. The volume 'sharedvol' was not created before running containers
D. Files created by c1 are not saved because the container is stopped
Solution
Step 1: Check volume creation requirement
Named volumes must exist or be created automatically. If 'sharedvol' was never created, Docker creates an empty volume.
Step 2: Understand volume persistence and sharing
If 'sharedvol' was not created or data was not saved properly, c2 won't see c1's files. Network does not affect volume sharing.
Final Answer:
Files created by c1 are not saved because the container is stopped -> Option D
Quick Check:
Stopped container does not save files to volume [OK]
Hint: Files must be saved and container running to share data [OK]
Common Mistakes:
Thinking network affects volume sharing
Assuming mount syntax is wrong
Believing stopped containers save files automatically
5. You want to share a folder /var/log/app on your host with multiple containers using a named volume. Which sequence of commands correctly creates and uses the named volume to achieve this?
hard
A. docker volume create app_logs
docker run -d -v /var/log/app:/app/log busybox sleep 1000
B. docker volume create --opt type=none --opt device=/var/log/app --opt o=bind app_logs
docker run -d -v app_logs:/app/log busybox sleep 1000
C. docker volume create app_logs
docker run -d -v app_logs:/var/log/app busybox sleep 1000
D. docker run -d -v app_logs:/app/log busybox sleep 1000
Solution
Step 1: Create a named volume that binds to host folder
Use docker volume create with options type=none, device=/var/log/app, and o=bind to bind the host folder to the volume.
Step 2: Run container mounting the named volume
Mount the named volume app_logs to the container path /app/log with -v app_logs:/app/log.