1

This issue is similar to one posted a couple of years ago but with a slight difference. I'm trying to identify how to spin up a Docker container which has an NFS Volume mount whether or not the NFS server is online.

I have a Docker volume that I have created from an NFS mount to a device which comes on and off the network at regular intervals:

docker volume create --driver local --opt type=nfs --opt o=addr=192.168.2.237,rw,soft,timeo=10,bg --opt device=:/media raspberryPi

In my mount options, I have intentionally specified a soft mount such that if the mount is not available, an error will return to the process running within the container and the application will handle the I/O error.

In theory, my setup works fine IFF the container is started when the NFS mount is present.

[eric@docker1 tmp]$ docker run --rm -it -v raspberryPi:/pi ubuntu bash
root@f8fd958740da:/# ls /pi
lost+found  x  y

If remove the device from the network, the NFS access fails from within the container (as expected):

root@f8fd958740da:/# ls /pi
ls: cannot access '/pi': Stale file handle

If I re-attach the device to the network, then the resource becomes available again, and everything continues to work.

The problem arises, however, if the NFS volume is NOT present at container start time. If it isn’t present, then the container fails to launch altogether:

[eric@docker1 tmp]$ docker run --rm -it -v raspberryPi:/pi ubuntu bash
docker: Error response from daemon: error while mounting volume '/var/lib/docker/volumes/raspberryPi/_data': error while mounting volume with options: type='nfs' device=':/media/movies' o='addr=192.168.2.237,rw,soft,timeo=10': operation not supported.

Is there anyway I can configure docker to “ignore” the volume mount error and continue to mount it none-the-less? I tried using a background mount in the options, but that did not help. Essentially, I would like the container to launch with a mount configured to /pi even though the NFS Server is offline (similar to behaviour if the server is online and taken offline while the container is live).

1 Answer 1

1

No can do. You need to have all available bindings on container start. Imagine if the same happened with a port binding? Or a network binding even?

You can attempt to mount the nfs folder after the container boots, have the NFS IP and paths as an env var, craft a script and bake it into the container or in some trusted storage that you can pull, like github.

This solution will boot the container but won't mount the files, which is what I'm assuming you need.

You would commit to a public repo or gist something like this:

#! /bin/bash

mount -t nfs -o proto=tcp,port=$NFS_PORT $NFS_IP:$NFS_PATH_REMOTE $NFS_PATH_LOCAL
bash

Then you could run

docker run --rm -it -e $NFS_PORT=2049 -e $NFS_IP=192.168.2.237 -e $NFS_PATH_REMOTE=/media -e $NFS_PATH_LOCAL=/pi ubuntu curl https://raw.githubusercontent.com/eric-b/docker-scripts/master/mount-nfs.sh | bash

That's all because I'm assuming you're running this from a remote environment, very likely a raspberrypi if you're running this from your local machine, you could have a file called .env-nfs

NFS_PORT=2049
NFS_IP=192.168.2.237
NFS_PATH_REMOTE=/media 
NFS_PATH_LOCAL=/pi
NFS_SCRIPT=https://raw.githubusercontent.com/eric-b/docker-scripts/master/mount-nfs.sh

And run

docker run --rm -it -env-file ./env-nfs ubuntu curl $NFS_SCRIPT | bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.