Create volume:
$sudo docker volume create volume-b1
volume-b1
Inspect a Volume
$ sudo docker inspect volume-b1
[
{
"CreatedAt": "2022-08-17T09:52:47+05:30",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/volume-b1/_data",
"Name": "volume-b1",
"Options": {},
"Scope": "local"
}
]
list a volume:
$sudo docker volume ls
DRIVER VOLUME NAME
local vol-busybox
local volume-b1
delete a volume:
$sudo docker volume rm volume-b1
Mount the driver to a container
- -v or --volume : contains all fields and also order should be maintained
- name of the volume
- path
- options like ro--(read-only)
$ sudo docker run -d --volume vol-ubuntu:/tmp ubuntu
14efcc03cc75c98877f1074bc30d3570b4f062c122cccb83272409d677c9ae4c
- --mount: Separate fields , and contains as key-value pair, order is not important, easier to understand.
$ docker service create \
--mount 'type=volume/bind/tempfs,src=<VOLUME-NAME>,dst=<CONTAINER-PATH>,volume-driver=local,volume-opt=type=nfs,volume-opt=device=<nfs-server>:<nfs-path>,"volume-opt=o=addr=<nfs-address>,vers=4,soft,timeo=180,bg,tcp,rw"'
--name myservice \
<IMAGE>
$ sudo docker run -d --name devtest --mount source=myvol2,target=/app nginx:latest
8639e7cc80f422fdbc00b7209a3f976368af7692d38f75b4310b81961c27fc11
*inspect volume: *
$ sudo docker inspect myvol2
[
{
"CreatedAt": "2022-08-17T10:37:28+05:30",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/myvol2/_data",
"Name": "myvol2",
"Options": null,
"Scope": "local"
}
]
Top comments (0)