Ubuntu 20.04
Sponsored Link

Docker : Use External Storage (NFS)2020/06/02

 
This is an example to use NFS External Storage.
[1]
NFS server is required to be running on your LAN, refer to here.
On this example, configure [/home/nfsshare] directory on [nfs.srv.world] as a shared directory.
[2] Create a volume for NFS and use it.
# create [nfs-volume] volume

root@dlp:~# docker volume create \
--opt type=nfs \
--opt o=addr=10.0.0.35,rw,nfsvers=4 \
--opt device=:/home/nfsshare nfs-volume 
nfs-volume

# display volume list

root@dlp:~#
docker volume ls

DRIVER    VOLUME NAME
local     nfs-volume

# display details of [nfs-volume]

root@dlp:~#
docker volume inspect nfs-volume

[
    {
        "CreatedAt": "2021-05-12T05:30:49Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/nfs-volume/_data",
        "Name": "nfs-volume",
        "Options": {
            "device": ":/home/nfsshare",
            "o": "addr=10.0.0.35,rw,nfsvers=4",
            "type": "nfs"
        },
        "Scope": "local"
    }
]

# run container with mounting [nfs-volume] to [/nfsshare] on container

root@dlp:~#
docker run -it -v nfs-volume:/nfsshare ubuntu
root@7be982c34dd1:/#
df -hT /nfsshare

Filesystem      Type  Size  Used Avail Use% Mounted on
:/home/nfsshare nfs4   20G  6.4G   13G  35% /nfsshare

# verify reading and writing

root@7be982c34dd1:/#
echo "NFS Volume Test" > /nfsshare/testfile.txt

root@7be982c34dd1:/#
cat /nfsshare/testfile.txt

NFS Volume Test
Matched Content