By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Create and manage named and anonymous volumes to persist data in Docker containers. docker volume create
docker info | grep Volumes
docker volume ls
docker run -v myvolume:/data alpine echo "Hello World"
docker inspect -f '{{.Mounts}}' <container_id>
docker rm <container_id>
docker run -v /tmp/data:/data alpine echo "Hello World"
Purpose: Store web server logs Command: docker volume create logsFlags: None Explanation: Creates a named volume called "logs" that can be used by containers.
Purpose: Store database data Command: docker run -v /tmp/data:/data -d postgres Flags: -v mounts the anonymous volume, -d runs the container in detached mode Explanation: Creates an anonymous volume in /tmp/data and mounts it to the /data directory in the container.
docker run -v /tmp/data:/data -d postgres
-v
-d
/tmp/data
/data
Purpose: Store files Command: docker run -v myfiles:/data -d nginx Flags: -v mounts the named volume, -d runs the container in detached mode Explanation: Creates a named volume called "myfiles" and mounts it to the /data directory in the container.
docker run -v myfiles:/data -d nginx
Error message: "Volume not found" Why it happens: The volume was not created or does not exist Fix: docker volume create
Error message: "Permission denied" Why it happens: The container does not have permission to access the volume Fix: docker run -v <volume_name>:/data --user <username> <image>
docker run -v <volume_name>:/data --user <username> <image>
Error message: "Volume not mounted" Why it happens: The volume was not mounted correctly Fix: docker inspect -f '{{.Mounts}}' <container_id>
Situation: You created a named volume but want to verify it exists Command: docker volume ls Correct response: The volume name is listed in the output
Situation: You created a container and a volume but want to verify the container can access the volume Command: docker inspect -f '{{.Mounts}}' <container_id> Correct response: The volume is listed in the output with the correct mount path
Situation: You deleted a volume but want to verify it is gone Command: docker volume ls Correct response: The volume name is not listed in the output
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.