a lot of my containers depend on data that exist on NFS shares. So when restarting the machine, if the docker service starts before all the NFS shares have been mounted, the containers cannot start.
so I need a way to mount all the NFS shares before starting the docker service. So I modified this file
Why are you even trying to mount your nfs shares uing systemd, rather the /etc/fstab? I never had a timing problem with mounts in /etc/fstab - except stale connections from time to time.
Because of the stale connections, I moved over to use a nfs volume, declared in my compose file:
But I am using /etc/fstab to mount the NFS share. Still, the docker service starts before /etc/fstab manages to mount the NFS share. So I just login on the machine run systemctl restart docker and everything is fine.
I also tried your suggestion to mount the share as an NFS volume in docker, like this
docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.29,rw --opt device=:/media media
and the volume is created under /var/lib/docker/volumes but it’s empty. Shouldn’t it contain the files I have in my NFS share? (\192.168.1.29\media)
Odd that you are having problems with mount in /etc/fstab. Never had any problems (except the stale share ofcourse) when I rebooted the machines after a couple of months.
If no container using that volume is started, you will only see the metadata file opts.json, which holds the details to mount the remote share. Once a container using that volume is started, you should see the content in the _data subfolder.
I realize we’re 5 years in the future, but this unhelpful reply still pops-up at the top of Google and I feel like you don’t/didn’t realize that during something like catastrophic power loss, not all systems come back up at the same time and so might not have those NFS shares ready to be mounted. So while it’s great that you’ve never had the problem, I really hope you’ve had the kind of personal growth that helps you address the problem someone is having instead of just going ‘oh, funny, I never have that problem’ and waste all of our time 5 years in the future.
Another less elegant way to do this is to edit the systemd docker service config and add your required NFS mounts as entries for “After” and “Requires”.
Use systemctl edit docker.service (and don’t directly edit systemd files) to have this persist through updates.