DEV Community

bhargavirengarajan21
bhargavirengarajan21

Posted on

Docker storage commands?

Create volume:

$sudo docker volume create  volume-b1
volume-b1
Enter fullscreen mode Exit fullscreen mode

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"
    }
]
Enter fullscreen mode Exit fullscreen mode

list a volume:

$sudo docker volume ls

DRIVER    VOLUME NAME
local     vol-busybox
local     volume-b1

Enter fullscreen mode Exit fullscreen mode

delete a volume:

 $sudo docker volume rm volume-b1
Enter fullscreen mode Exit fullscreen mode

Mount the driver to a container

  1. -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

Enter fullscreen mode Exit fullscreen mode
  1. --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>
Enter fullscreen mode Exit fullscreen mode
$ sudo docker run -d   --name devtest   --mount source=myvol2,target=/app   nginx:latest
8639e7cc80f422fdbc00b7209a3f976368af7692d38f75b4310b81961c27fc11
Enter fullscreen mode Exit fullscreen mode

*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"
    }
]

Enter fullscreen mode Exit fullscreen mode

Top comments (0)