---
tags:
- containers
- l1
- flashcard-deck
- docker-storage
---
<!-- wiki:breadcrumb:start -->
[Portal](../../../../library/portal/index.md) | **Level:** [L1: Foundations](../../../../library/portal/levels.md) | **Topics:** [Containers Deep Dive](../../../../library/portal/topics.md) | **Domain:** containers
<!-- wiki:breadcrumb:end -->

id	category	difficulty	tags	question	answer	source_path
docker-storage/266b800b5765	docker-storage	hard	docker-storage, cli-options	Explain the purpose of the "-v" option in the "docker run" command.	The -v (or --volume) option in the docker run command is used to create a bind mount or associate a container path with a volume. It allows you to share data between the host machine and the container. \nExample of using a bind mount: \n```docker run -v /host/path:/container/path image_name``` \nExample of using a volume: \n```docker run -v volume_name:/container/path image_name``` \nThis option is versatile and can be used to connect a container to either a host path or a named volume.	projects/knowledge/interview/docker/168-explain-the-purpose-of-the-v-option-in-the-docker-.txt
docker-storage/3f4ccc12e13c	docker-storage	medium	docker-storage, volumes	Explain the difference between "docker volume ls" and "docker volume rm."	`docker volume ls:`\nLists all Docker volumes, including named and anonymous volumes. \n`docker volume rm:`\nRemoves one or more specified volumes. \nWhile docker volume ls provides an overview of all volumes on the system, docker volume rm is used to remove specific volumes. It's important to note that removing a volume also removes any data stored in that volume. projects/knowledge/interview/docker/172-explain-the-difference-between-docker-volume-ls-an.txt	
docker-storage/5a7793569e9a	docker-storage	medium	docker-storage, volumes	What is a Docker volume?	A volume is a mechanism for persistent data storage outside of the container's layered filesystem. It's a designated folder that can be mounted into containers, allowing data to persist and be shared among containers or between host and container. (E.g., docker run -v /host/path:/container/path ...).\n\nUnder the hood: Docker volumes live at /var/lib/docker/volumes/ on the host. They bypass the union filesystem, giving better I/O performance than the writable container layer.\n\nRemember: three types of storage: volumes (Docker-managed), bind mounts (host path), tmpfs (RAM only). Volumes are preferred for persistent data.	projects/knowledge/interview/docker/208-what-is-docker-volume.txt
docker-storage/5d5b4d1198db	docker-storage	easy	docker-storage, storage, fundamentals	You stopped a running container but, it still uses the storage in case you ever resume it. How to reclaim the storage of a container?	In order to reclaim the storage of a container, you have to remove it.\n\nUnder the hood: stopped containers keep their writable layer on disk. Only docker rm frees it. Check: docker system df.	projects/knowledge/interview/docker/082-you-stopped-a-running-container-but-it-still-uses-.txt
docker-storage/627ccb47e887	docker-storage	medium	docker-storage, volumes, persistence	How can you persist data in a Docker container using volumes?	To persist data in a Docker container using volumes, you can follow these steps: \nCreate a Volume: \n```docker volume create my_data_volume``` \nRun a Container with the Volume: \n```docker run -v my_data_volume:/path/in/container my_image``` \nThis ensures that the data in /path/in/container is stored in the my_data_volume volume. Even if the container is removed, the data persists in the volume.	projects/knowledge/interview/docker/169-how-can-you-persist-data-in-a-docker-container-usi.txt
docker-storage/76d178a4ea4c	docker-storage	medium	docker-storage, bind-mounts, volumes	What is a Docker volume, and how is it different from a bind mount?	A Docker volume is a persistent data storage mechanism that allows data to be shared between containers and persisted even if the containers are stopped or removed. Volumes are managed by Docker and are stored outside the container filesystem. \n**Key differences from a bind mount:**\n* Persistence: Data in volumes persists even if the container is removed, while bind mounts depend on the host filesystem and are subject to host changes.\n* Managed by Docker: Volumes are managed by Docker and are more suitable for long-term data storage. Bind mounts are simply references to a path on the host.\n* Performance: Volumes are typically more performant than bind mounts, especially in scenarios with large amounts of data.	projects/knowledge/interview/docker/166-what-is-a-docker-volume-and-how-is-it-different-fr.txt
docker-storage/85cce78bbeca	docker-storage	medium	docker-storage, ephemeral	True or False? Containers have ephemeral storage layer	True. The ephemeral storage layer is added on top of the base image layer and is exclusive to the running container. This way, containers created from the same base image, don't share the same storage.\n\nUnder the hood: the ephemeral layer uses a copy-on-write filesystem (overlay2 by default). Writes go to the thin writable layer; reads fall through to the image layers below.\n\nGotcha: writing heavily to the ephemeral layer is slow and bloats the container. Use volumes for any significant I/O.	projects/knowledge/interview/docker/090-true-or-false-containers-have-ephemeral-storage-la.txt
docker-storage/91592cff38ff	docker-storage	hard	docker-storage, storage, fundamentals	How to mount a directory from the host to a container?	```\nCONTAINER_BINARY=podman\nmkdir /tmp/dir_on_the_host\n\n$CONTAINER_BINARY run -v /tmp/dir_on_the_host:/tmp/dir_on_the_container IMAGE_NAME\n```\n\nIn some systems you'll have also to adjust security on the host itself:\n\n```\npodman unshare chown -R UID:GUID /tmp/dir_on_the_host\nsudo semanage fcontext -a -t container_file_t '/tmp/dir_on_the_host(/.*)?'\nsudo restorecon -Rv /tmp/dir_on_the_host\n```	projects/knowledge/interview/docker/084-how-to-mount-a-directory-from-the-host-to-a-contai.txt
docker-storage/9b24778c6070	docker-storage	medium	docker-storage, volumes, named-volumes	What is the significance of named volumes in Docker?	Named volumes in Docker provide a way to assign a human-readable name to a volume, making it easier to manage and reference. Unlike anonymous volumes, named volumes persist even if no containers are using them, allowing for better organization and data retention. \nExample of creating a named volume: \n```docker volume create my_named_volume``` \nThis creates a named volume named my_named_volume. You can then use this volume with the docker run command or other Docker-related operations.	projects/knowledge/interview/docker/170-what-is-the-significance-of-named-volumes-in-docke.txt
docker-storage/9c97ac0a1027	docker-storage	medium	docker-storage, ephemeral	Container storage is said to be ephemeral. What does it mean?	It means the contents of the container and the data generated by it, is gone when the container is removed.\n\nAnalogy: a container's storage is like a whiteboard — you can write on it while it's in use, but when you erase the board (remove the container), everything is gone.\n\nRemember: 'Ephemeral = temporary.' Containers are designed to be disposable. Persist important data with volumes, not the container's writable layer.\n\nGotcha: docker stop preserves the writable layer (data survives restart). Only docker rm destroys it.	projects/knowledge/interview/docker/080-container-storage-is-said-to-be-ephemeral-what-doe.txt
docker-storage/a3a3418f0d56	docker-storage	easy	docker-storage, volumes	How to create a new volume?	```\nCONTAINER_BINARY=podman\n$CONTAINER_BINARY volume create some_volume\n```\n\nUnder the hood: named volumes are preferred — managed by Docker, portable, survive removal. Better than anonymous volumes.	projects/knowledge/interview/docker/083-how-to-create-a-new-volume.txt
docker-storage/e37b7cd56a8f	docker-storage	medium	docker-storage, volumes	How do you create a Docker volume?	To create a Docker volume, you can use the docker volume create command: \n```docker volume create my_volume``` \nThis command creates a named volume named my_volume. You can then use this volume when running containers to share and persist data. \n```docker run -v my_volume:/path/in/container my_image``` \nThis mounts the my_volume volume to a specified path inside the container.	projects/knowledge/interview/docker/167-how-do-you-create-a-docker-volume.txt
docker-storage/e4e89762e24d	docker-storage	hard	docker-storage, drivers	How does Docker handle storage drivers, and what are some commonly used drivers?	Docker uses storage drivers to manage how container filesystems are stored and managed. Storage drivers interface with the underlying storage infrastructure to provide container filesystem capabilities. \n**Commonly used Docker storage drivers include:**\n* Overlay2: Default on most Linux distributions, provides a good balance of performance and functionality.\n* aufs: Older driver, historically used on Ubuntu systems.	projects/knowledge/interview/docker/190-how-does-docker-handle-storage-drivers-and-what-ar.txt
docker-storage/e6ddc864c3e0	docker-storage	hard	docker-storage, volumes, backup	How do you backup and restore data from Docker volumes?	To backup and restore data from Docker volumes, you can use standard filesystem backup tools or Docker-specific utilities. Here's a general approach: \nBackup: \n* Use a backup tool to copy the contents of the volume to a backup location. For example: \n```docker run --rm -v source_volume:/backup -v /local/path:/restore alpine tar cvf /backup/data.tar /data```\nRestore:\n* Use the backup tool to restore the contents to a named volume: \n```docker run --rm -v target_volume:/target -v /local/path:/restore alpine tar xvf /restore/data.tar -C /target```	projects/knowledge/interview/docker/171-how-do-you-backup-and-restore-data-from-docker-vol.txt
docker-storage/e741e419f004	docker-storage	medium	docker-storage, persistence	True or False? Applications running on containers, should use the container storage to store persistent data	False. Containers are not built to store persistent data and even if it's possible with some implementations, it might not perform well in case of applications with intensive I/O operations.\n\nRemember: 'Containers for compute, volumes for data.' The container writable layer uses copy-on-write, which adds overhead for write-heavy workloads.\n\nExample: a database should write to a Docker volume (or bind mount), not to the container filesystem. The volume bypasses the overlay driver for better I/O.	projects/knowledge/interview/docker/081-true-or-false-applications-running-on-containers-s.txt
docker-storage/ece934d00572	docker-storage	easy	docker-storage, storage, fundamentals	True or False? podman diff works only on the container filesystem and not mounted files	True. For mounted files you can use `podman inspect CONTAINER_NAME/ID`\n\nUnder the hood: volumes exist outside the overlay filesystem. podman diff only sees the container's own writable layer.	projects/knowledge/interview/docker/052-true-or-false-podman-diff-works-only-on-the-contai.txt
docker-storage/f240f40b8bc9	docker-storage	easy	docker-storage, volumes	What are Docker "volumes"?	Storage used to persist data outside of containers.\n\nUnder the hood: volumes live at /var/lib/docker/volumes/ and survive container removal.\n\nExample: docker run -v mydata:/app/data nginx — data persists across container restarts.	projects/knowledge/interview/docker/205-docker-volumes.txt

<!-- wiki:related:start -->
---

## Wiki Navigation

### Related Content

- [Containers Deep Dive](../../../../library/topics/containers-deep-dive/index.md) (Topic Pack, L1) — Containers Deep Dive
- Docker Security Flashcards *(CLI)* (flashcard_deck, L1) — Containers Deep Dive

<!-- wiki:related:end -->
