Imagine that you would like to run the database as a container. You can start such a container and enter the data. Where is it stored? What happens when you stop the container or remove it? You can start the new one, but the database will be empty again. Unless it's your testing environment, you don't expect such a scenario.
Docker volume is the Docker host's directory mounted inside the container. It allows the container to write to the host's filesystem as it was writing to its own. The mechanism is presented in the following diagram:
Docker volume enables the persistence and sharing of the container's data. Volumes also clearly separate the processing from the data.
Let's start with an example and specify the volume with the -v <host_path>:<container_path> option and connect to the container:
$ docker run -i ...