Index Keywords Recent

↶ Return Home

Mounting NFS Volumes with Docker

Last Updated July 17th 2022, 11:48:17 am

Description

This article documents how to mount an NFS volume to a docker container using docker compose or docker stack with a docker-compose.yml file.[1]

You may see issues where the volumes are not automatically updated in the container when the data changes on the host.[1:1]

Make sure the NFS share/folder exists on the server before attempting to mount it.

Don’t remove ‘soft’ and ‘nolock’ unless you’re sure you know what you’re doing - this stops docker from freezing if your NFS server goes away.[1:2]

Examples

Example docker-compose.yml[1:3]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: "3.2"

services:
rsyslog:
image: jumanjiman/rsyslog
ports:
- "514:514"
- "514:514/udp"
volumes:
- type: volume
source: example
target: /nfs
volume:
nocopy: true
volumes:
example:
driver_opts:
type: "nfs"
o: "addr=10.40.0.199,nolock,soft,rw"
device: ":/docker/example"

Example docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
version: "3.5"
services: # $ docker stack deploy -c docker-compose.yml calibre
calibre:
image: lscr.io/linuxserver/calibre:arch-version-1b31d319
ports:
- 8091:8080
- 8092:8081
environment:
- PUID=1000
- PGID=1000
- TZ=America/Los_Angeles
- PASSWORD= #optional
- CLI_ARGS= #optional
volumes:
- type: volume
source: library
target: /config
volume:
nocopy: true
volumes:
library:
driver_opts:
type: "nfs"
o: "addr=10.32.25.64,nolock,soft,rw"
device: ":/media/anthony/data-share/nfs/calibre"

  1. https://stackoverflow.com/a/46481637 ↩︎ ↩︎ ↩︎ ↩︎