Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. A volume allows data to persist, even when a container is deleted. Volumes can be used to share data between the host and the container(s).
By mounting a volume you can achive to
- Pull data from a container.
- Push data to a container.
- Share data between containers.
Please note that, arguments prefixed with @(at) in below commands must be replaced with actual values.
docker run -it --name [@container-name] -v [@directory-in-host-machine]:/[@directory-available-in-container] [@image-name] /bin/bash
docker volume create --name [@volume-name]
docker run -it --name [@container-name] -v [@volume-name]:/[@directory-available-in-container] [@image-name] /bin/bash
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
# create a volume
VOLUME /@directory-in-the-container
docker build -t [@image-name] .
docker run -it --name [@container-name] [@image-name] /bin/bash
Step 4: Use docker inspect command to see destination(directory in the container) and source(directory on the host machine) folders for created volume
docker inspect [@container-name]