To better understand volumes in Docker, let me explain how the file systems are stored in Docker. Docker images would be stored as a series of read-only layers. When a container gets initiated it adds a layer of the read-write layer above this read-only layer and superposes it rather but doesn’t destroy it. Combined these two layers are called the Union file system. So, when this container gets deleted by any chance then all the changes to it get deleted with it and when that Docker image is reinitiated, it starts afresh with a new container.
For the purpose of persisting this data, Docker introduced volumes which act as a directory or file to store the information on the host file system as normal directories, outside this union of the file system.
If you wish to learn Docker and get yourself certified, then head onto the Intellipaat website to join the Docker training from Intellipaat.
Also, check out our YouTube video on Docker training to help you understand in a better way.