Get started with Docker volumes
What is docker Volume ?
Docker volumes is a mechanism by which data generated / used by the docker containers are stored. Docker Volumes work both on windows and linux platforms.The reason why volumes are used predominantly in the industry is because it enables us to share data between two containers . It basically decouples a container from a storage . On deleteing container , the volume wont get deleted.
Why docker volume?
When you run docker containers the data with respect to the insance will be saved within the containers and whenever we stop / delete / remove that particular instance the data will be deleted, However in realtime scenarios we would need to stop / delete containers without loosing the data, It should be possible to create new containers with same data or sharing of data between containers should be possible . In these use cases docker volume plays an integral part.
Now Let’s see how to use docker volumes ,
docker volume create <Volume_Name
This command will create a new docker volume.
docker volume ls
List down all the docker containers available in the machine.
docker volume inspect <Volume_Name>
To inspect the details of created docker volume , Mount point will give you the path where the volume is stored in system.
docker volume rm <Volume_Name>
doker volume prune
docker volume rm <name> will remove specific volume whereas prune will remove all unused docker volumes.
Add -v <VolumeName> or -volume <VolumeName> to attach the created volume to a container instance ,
docker run <ContainerName> --name devtest -v <VolumeName>
These are the very basic and handy commands related to docker volumes . You can read more on this here