How to Set Docker's Default NFS Share Version to 4 or 4.2?

May 7, 2025 3 answers
Asked by CuriousCat123
I've been having some trouble getting a Docker service up and running that requires `xattr`s. It seems to me (although I haven't verified it) that even if my host mounts NFS volumes with version 4 by default, Docker (along with Docker Compose and Portainer) defaults to mounting with version 3. Is there any way to change this default NFS mount version to 4 or even 4.2? I'm using Fedora CoreOS / uBlue, and adjusting this would save me from having to specify the version for every single NFS mount.

Answers

TechGuru99
The options you provide to Docker are what's sent to the kernel when mounting. Docker doesn't really modify this much, aside from resolving hostnames. So, unfortunately, you canโ€™t change the default behavior unless you're willing to dive into patching the kernel NFS module.
Reply to this answer
NFSWizard77
I always add something like this in my compose file: ``` volumes: irisdata: driver: local driver_opts: type: nfs o: "addr=10.10.10.10,nfsvers=4" device: ":/home/w453y/mydata" ``` This way, I ensure Iโ€™m using version 4 when needed. Just a heads up, if you need `xattr` support, youโ€™ll have to explicitly set it to 4.2. Also, remember to add `,soft,nolock`; otherwise, if the NFS gets stuck, it could hang your entire Docker setup!

QuickFixXpert: For sure, that's a solid approach! Iโ€™m in a similar boat, needing to use 4.2 for the `xattr` functionality as well.

Reply to this answer
NFSMountMaster
I usually mount the NFS directly onto the virtual machine that's running the Docker containers. Is it better to handle the mounting within the compose file instead?
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions