Docker containers store data in their writable layer, which is removed when the container is deleted. Docker provides persistent storage options to keep data available even after the container's lifecycle ends.
- Docker Volumes: Docker-managed storage used to persist container data independently of the container.
- Bind Mounts: Maps a specific file or directory from the host filesystem to a location inside the container.
- Other Options: Docker also supports tmpfs mounts on Linux and named pipes on Windows.

1. Docker Volume
Docker volumes are Docker-managed storage locations mounted into containers to persist data. They are the preferred storage method because they provide good performance and keep container data isolated from other host processes.
We can use the following command to create docker volume
docker volume create We can mount a volume to multiple containers simultaneously and Docker doesn't remove them even if they're not being used by any running container. To remove a volume, we can use the following command -:
docker volume pruneIn a Linux filesystem, we can find the available volumes at the following path '/var/lib/docker/volumes/ ', while in Windows, we can get the location of the volume by running the following command in file explorer -:
\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumesTo learn more about volumes and how to mount them to a container click here.
2. Bind Mounts
Bind mounts allow Docker containers to share files or directories directly with the host filesystem. They are useful when containers need to access or modify specific host files.
- Host Access: Mounted files can be accessed by both containers and non-Docker processes.
- Host Path: Requires a specific absolute path on the host filesystem.
- Limited Management: Cannot be managed as easily through Docker CLI as Docker volumes.
- Security Risk: Containers can modify or delete files on the host, potentially affecting other processes.
3. tmpfs mounts
tmpfs mounts provide temporary storage for containers by keeping data in the host machine's memory instead of on disk. They are mainly used on Linux when data does not need to persist.
- Temporary Storage: Data exists only while the container is running.
- Memory-Based: Stores data in the host's RAM rather than the filesystem.
- Linux Only: Primarily available when using Docker on Linux.
- No Sharing: Data cannot be shared between multiple containers.
4. Named pipes
Named pipes are a special type of mount used mainly with Docker on Windows to enable communication between containers and host processes.
- Communication: Enables data exchange between containers and host processes.
- Windows: Primarily used with Docker on Windows.
- Not Persistent Storage: Unlike volumes, named pipes are designed for communication, not storing container data.
| Feature | Docker Volume | Bind Mount | tmpfs Mount | Named Pipe |
|---|---|---|---|---|
| Definition | Docker-managed storage for persistent data | Maps a host file/directory to a container | Temporary storage in host memory (RAM) | Communication mechanism between host and container processes |
| Storage Location | Docker-managed area on host | Specific host filesystem path | Host memory (RAM) | Host pipe |
| Data Persistence | Persists after container removal | Persists on host | Removed when container stops | Not intended for data persistence |
| Managed by Docker | Yes | Limited | Yes | Yes |
| Host File Access | Limited/direct access not intended | Directly accessible | No | Used for communication |
| Sharing | Can be shared between containers | Can be shared | Cannot be shared between containers | Used for process communication |
| Platform | Linux & Windows | Linux & Windows | Mainly Linux | Mainly Windows |
| Best Use | Databases and persistent application data | Development and sharing host files | Temporary or sensitive data | Host-container communication |