How to mount nfs drive in container: simplest way

In a simplistic fashion, nfs mounts can be achieved by a compose file like this:

version: "3.5"

services:
  builder:
    image: my_build
    volumes:
      - "nfsmountCC:/opt/"    # nfsmountCC is the volume created by docker-compose in the volumes section below.  /opt/ is the mount location inside of the container.
                                           
volumes:
  nfsmountCC:
    driver: local
    driver_opts:
      type: nfs
      o: addr=10.90.239.72       # IP of nfs server.  This is also where you put any options '-o' in standard option format
      device: ":/opt/compilers/"  # location on nfs server of file/dir you want to mount

Obviously remove the ‘#’ comments… they are for explanation only

I really hope this helps somebody. I had issues with finding the starting point, it seemed everyone had a different way of doing this simple task.

7 Likes