First, fetch the docker file. e.g. https://github.com/tai271828/dockerized_nfs_server
And then build the docker image by
docker build -t <the container name you want to have> .
Then fix
this source code start.sh to rename mynfs to be
<the container name you want to have>.
Follow the README to start the container to have the nfs service. Before starting the container, make sure you native host has the kernel which supports NFS service. Take Ubuntu 16.04 as an example, NFS service still needs the support from kernel. Use
ps aux | grep nfsd on your native host to see the NFS support from kernel is already there or not. If no, you may insert the nfsd kernel module to have the NFS support from kernel:
sudo modprobe nfsd
Otherwise you may have the following error message when trying to mount the NFS folders provided by the NFS container:
mount.nfs: timeout set for Sun Nov 6 13:54:20 2016
mount.nfs: trying text-based options 'proto=tcp,port=2049,vers=4,addr=172.17.0.2,clientaddr=172.17.0.1'
mount.nfs: mount(2): Connection refused