Docker Storages - Overview

In Docker all the data is abstracted and stored at container lever. The lifecycle of those data is tightly coupled with container which means as soon as the container is deleted data is lost. This leads us to the need of storage where the data can be persisted outside container lifecycle.

Docker allows this in 3 ways:

  • Volumes
  • Bind mounts
  • Tmpfs


Docker volume (Image from

For volumes, data is stored inside the host’s file system area managed by docker. Usually its /data/var/lib/docker/volumes .

  • Volumes are preferred since the storage location is managed by docker
  • Volumes can be created explicitly or while creating the container

Volumes can be created using specifying-v or — -mount flag.
For -v flag, there are 3 fields:

  • Name of the volume. Anonymous volumes also can be created, in which docker will name it uniquely.
  • Path where directory/file is mounted inside the container. e.g. In case of MSSQL its the data path where the data is stored.
  • [Optional] Comma separated options list. e.g. ro is given for read only volumes

For --mount , there are a list of key value pairs:

  • source : Name of the volume. Omit this field to create anonymous volume.
  • destination : path where the file/directory is mounted in the container
  • type : The value is volumealways.

Note: The difference between -v and --mount is that latter is more verbose and hence easy to understand.

docker volume create <vol_name> // <vol_name> should be replaced by     name of volume
//using -v
docker run -v <vol_name>:<destination_path> <image>
//using --mount
docker run --mount source=<vol_name>,target=<destination_path>,type=volume <image>
docker inspect <vol_name>
docker volume rm <vol_name>

Bind Mounts

Bind mounts (Image from

In bind mounts, the data can be stored anywhere in host’s filesystem other than the area managed by docker. While creating the bind mount absolute file path w.r.t host should be given as the source.

docker run --mount type=bind,source=<source_path>,target=<target_path> <image> // <source_path> should be replaced by absolute path. e.g. if the the folder is called target in current working directory, then it should be "$(pwd)"/target.



Fullstack developer | Microsoft certified | Sitecore certified

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store