Create volume:
docker volume create <volume-name>Mount container with Volume:
docker run /*cmds*/ --mount type=volume,src=<volume-name>,target=<path-in-container-to-store-volume> <image-name>Look at volume(s):
docker volume inspect
Mount:
docker run /*cmds*/ --mount type=bind,src="$(pwd)/secrets",target=/env <image-name>Where:
--mount
type=bind => bind mount
src="$(pwd)/secret" => sets source directory (on local fs) to <pwd>/secrets
target=/env => links(and creates) root/env dir in container, and links to src dir in local fs
| Volume | Bind Mount | |
|---|---|---|
| Storage | In a FS managed by docker | In the hosts FS |
| Access | Via docker only | Any process with FS access |
| Data sharing | Multiple container can use the same volume at the same time | Only one container can use the data at the same time |
| Use Cases | Cloud and remote friendly | Config, source code |