Today I started writing up a backupninja container for work. This container needs to be able to:
- Login into some of our prod boxes
- Store backup data on an NFS share
The logical choice for handling the back-end was to use autofs because of its ability to handle mounts that may drop out for whatever reason, and since we really need our storage available, doing a plain
mount is just not going to cut it.
So in my dockerfile,
apt-get install autofs
Additionally, autofs actually runs automounter in daemon mode. Since I’m using supervisor as my init, that needed to change:
BROWSE_MODE="no" /usr/sbin/automount -t 0 -f /etc/auto.master
This command runs with the same parameters as a basic autofs install on ubuntu (as defined by vars
/etc/default/autofs), with one exception,
-t. I don’t think a lot of people know this but autofs actually:
- Mounts the storage when you enter/ask for the storage/mountpoint
- Actually unmounts after a specified period of time, defined by the
Keeping that in mind, setting
-t 0 disables unmounting. I like this as it decreases the time to mount when wanting to reuse the share at a later time. This kind of thing is useful in a fairly stable environment and especially nice when browsing to your mounts via a GUI.
With that out of the way, there is one more requirement before automounter will actually run correctly: loading the kernel module, autofs4 Unfortunately, this is not possible inside a docker container, yes, even a privileged one. I won’t get into why, but will say that:
- On ubuntu 14 systems, you’ll have to run a
modprobe autofs4on the host before autofs in your container will work. Note that you do not need autofs installed on the host to do this.
- On coreos systems, autofs4 is already loaded, presumably because of systemd automount
On all systems, you will need to run your container in
--privilegedmode!!! If you don’t, you’ll see the likes of:
/usr/sbin/automount: test mount forbidden or incorrect kernel protocol version, kernel protocol version 5.00 or above required.
Finally, I wanted to make note of how I handle defining my mounts to autofs. As you might know, the
/etc/auto.master file defines locations and associated files that define how to mount to those locations. For my purposes, I decided to just define a single file that lists the mount points I want autofs to handle:
## Setting up our autofs mount(s) RUN echo "/- /etc/auto.mounts" >> /etc/auto.master ADD auto.mounts /etc/auto.mounts
auto.mounts, we merely define each mount, one per line:
/mnt -fstype=nfs,nolock,rw,bg,soft,intr,timeo=5,retrans=5,actimeo=10,retry=5 nas.example.net:/var/shared /house -fstype=nfs,rw,bg,soft,intr,timeo=5,retrans=5,actimeo=10,retry=5 goliath:/mnt
For more information on setting up autofs, check out the ubuntu docs.