Answers: <p>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?</p>
  <p>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.</p>
  <p>This solution will boot the container but won't mount the files, which is what I'm assuming you need.</p>
  <p>You would commit to a public repo or gist something like this:</p>
  <pre><code>#! /bin/bash
  
  mount -t nfs -o proto=tcp,port=$NFS_PORT $NFS_IP:$NFS_PATH_REMOTE $NFS_PATH_LOCAL
  bash
  </code></pre>
  <p>Then you could run</p>
  <pre><code>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
  </code></pre>
  <p>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</p>
  <pre><code>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
  </code></pre>
  <p>And run</p>
  <pre><code>docker run --rm -it -env-file ./env-nfs ubuntu curl $NFS_SCRIPT | bash
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-01-12T12:19:59.937Z
Answers: 2022-01-12T12:19:59.937Z
Answers: Magus
Body: <p>This issue is similar to <a href="https://devops.stackexchange.com/questions/7970/how-do-i-make-nfs-volumes-reliable-in-docker">one posted a couple of years ago</a> 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.</p>
  <p>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:</p>
  <pre><code>docker volume create --driver local --opt type=nfs --opt o=addr=192.168.2.237,rw,soft,timeo=10,bg --opt device=:/media raspberryPi
  </code></pre>
  <p>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.</p>
  <p>In theory, my setup works fine IFF the container is started when the NFS mount is present.</p>
  <pre><code>[eric@docker1 tmp]$ docker run --rm -it -v raspberryPi:/pi ubuntu bash
  root@f8fd958740da:/# ls /pi
  lost+found  x  y
  </code></pre>
  <p>If remove the device from the network, the NFS access fails from within the container (as expected):</p>
  <pre><code>root@f8fd958740da:/# ls /pi
  ls: cannot access '/pi': Stale file handle
  </code></pre>
  <p>If I re-attach the device to the network, then the resource becomes available again, and everything continues to work.</p>
  <p>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:</p>
  <pre><code>[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.
  </code></pre>
  <p>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).</p>
  
Tags: <docker>
Title: How to start a container with NFS volume if NFS server is offline?
UserDisplayName: Eric B.
ThreadText: # How to start a container with NFS volume if NFS server is offline?
  
  (Asked by: username_0 on 2022-01-11)
  
  This issue is similar to [one posted a couple of years ago](https://devops.stackexchange.com/questions/7970/how-do-i-make-nfs-volumes-reliable-in-docker) 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.
  
  ```
  [username_0@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:
  
  ```
  [username_0@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).
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-12. Score: 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/username_0-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/username_0-b/docker-scripts/master/mount-nfs.sh
  
  ```
  
  And run
  
  ```
  docker run --rm -it -env-file ./env-nfs ubuntu curl $NFS_SCRIPT | bash
  
  ```
  
  
  ---
  
  