Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker.
When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container. This is similar to the way that bind mounts work, except that volumes are managed by Docker and are isolated from the core functionality of the host machine.
Docker volume advantages
Volumes are easier to back up or migrate than bind mounts.
You can manage volumes using Docker CLI commands or the Docker API.
Volumes work on both Linux and Windows containers.
Volumes can be more safely shared among multiple containers simultaneously
Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality
You can give a volume a name, or docker will assign one automatically (much like a container).
Docker volume use cases
Sharing data among multiple running containers. Volumes are only removed when you explicitly remove them.
When the docker host is not guaranteed to have a specific directory or file structure (i.e. Different versions of Linux might have different FS trees)
When you want to store on a cloud provider rather than locally
When you need to back up easily
Docker Volumes
Commands
docker volume create foo-vol
docker volume inspect foo-vol
docker volume rm foo-vol
docker volume ls
Start container with a volume
If you start a container with a volume that does not yet exist, Docker creates the volume for you.