Just specaluting.. is it possible to mount NFS through systemd and make docker service dependent from that mount?
Selfhosted
A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.
Rules:
-
Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.
-
No spam posting.
-
Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.
-
Don't duplicate the full text of your blog or github here. Just post the link for folks to click.
-
Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).
-
No trolling.
Resources:
- selfh.st Newsletter and index of selfhosted software and apps
- awesome-selfhosted software
- awesome-sysadmin resources
- Self-Hosted Podcast from Jupiter Broadcasting
Any issues on the community? Report it using the report flag.
Questions? DM the mods!
Sorry, I'm absolutely not a Linux expert :) I use /etc/fstab for the mounts, and to manually re-mount I run "mount -a".
I think this is the way!
I think that is a good question to write something positive about SystemD.
I start my services with SystemD. I also moved my containers and docker-compose stack to be started by systemd. And it does mounting and bind-mounts, too. So I removed things from /etc/fstab and instead created unit files for systemd to mount the network mounts. And then you can edit the service file that starts the docker-container and say it relies on the mount. SystemD will figure it out and start them in the correct order, wait until the network and the mounts are there.
You have to put some effort in but it's not that hard. And for me it's turned out to be pretty reliable and low maintenance.
The absolute easiest and simplest would be to modify your grub config to have a longer timer on the boot menu, effectively delaying them until the NAS is up.
That doesn't necessarily mean it's the best option- there are ways to make the actual boot process wait for mounts, or to stagger the WOL signals, or the solutions others have mentioned. But changing grub is quick and easy.
Try looking into "autofs".
Thanks! I've just set that up. That would seem to solve the solution, right, without reboots?
Yes. The important detail is that it remounts the path once the path gets called. So I setup a cron job to "ls" the path every few minutes to make sure it's always remounted quickly.
Best option is to delay docker startup until the mounts are ready.
Read systemd mounts and systemd dependencies.
It's been a while since I set it up, but from memory my mount point was set to be owned by root and immutable. That stopped any of my docker containers making new files and folders if the mounted drive or network location was not mounted or unavailable.
Yeah I used /etc/fstab which are static mounts.
I switched to autofs and that seems to be much better, as it does the mounts "at runtime", ie when requested.
Not sure how Docker behaves, but in a Stack/Compose file you can define volumes to use a specific driver, such as smb. E.g.:
volumes:
smb-calibre:
driver_opts:
type: "smb3"
device: "//mynas/ebooks/CalibreDB"
o: "ro,vers=3.1.1,addr=192.168.1.1,username=mbirth,password=secret,cache=loose,iocharset=utf8,noperm,hard"
So Docker will take care of mounting. Paired with restart: unless-stopped
, all my Containers come back online just fine after an outage.
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Fewer Letters | More Letters |
---|---|
DNS | Domain Name Service/System |
NAS | Network-Attached Storage |
Plex | Brand of media server package |
3 acronyms in this thread; the most compressed thread commented on today has 9 acronyms.
[Thread #509 for this sub, first seen 13th Feb 2024, 14:05] [FAQ] [Full list] [Contact] [Source code]
The other options of making the containers dependent on mounts or similar are all really better, but a simple enough one is to use SMB/CIFS rather than NFS. It's a lot more transactional in design so the drive vanishing for a bit will just come back when the drive is available. It's also a fair bit heavier on the overhead.
Using NFSv4 seems to work in similar fashion without the overhead though I haven't dug into the exact back and forth of the system to know how it differs from the v3 to accomplish that.
You can use bind mounts instead of volumes to prevent the container to start when the target is missing.
https://docs.docker.com/storage/bind-mounts/
I'm not sure what happens if the target goes down while the container is running. And you would still need a monitoring solution for telling the container to start when the target comes up.