Issue
i found this question first which is similar: How to mount an NFS share with rootless Podman?
long story short i am having trouble with rootless podman nfs volume. i am creating the volume with myuser
podman volume create --opt type=nfs4 --opt o=rw --opt device=my.server.ip.address:/data/nfs_data podman-nfs
but when trying to spawn a container using the volume i get a "mount.nfs: operation not permitted"
podman run -d -v podman-nfs:/tmp/data --name myapp myappimage:latest
i know that the nfs mount works because i managed to make it work manually. i used the user directive in fstab to allow myuser to mount it manually. i even managed to mount it manually in the path generated by podman (/home/myuser/.local/share/containers/storage/volumes/podman-nfs/_data)
the fstab entry looks like :
my.server.ip.address:/data/nfs_data /home/myuser/.local/share/containers/storage/volumes/podman-nfs/_data nfs rw,sync,user,noauto,_netdev 0 0
i could revert to a regular nfs mount on the filesystem and have podman use it like a file but i like the idea of having nfs managed by podman so it can gracefully close it if the container stops.
ADDITIONAL INFO : if i try using the --log-level=debug flag in podman run i get 'mount /bin/mount [...] failed with exit status 32'
as a side note i find it very weird that you can create volumes as a rootless podman user but cannot mount them. it feels like i'm missing something obvious. i found this howto which does it as root https://www.server-world.info/en/note?os=Rocky_Linux_8&p=podman&f=6
thank you for your time.
Solution
Me again.
I've figured it out. My understanding is that rootless podman cannot mount an NFS volume when starting a container even if the fstab has the user option for the mount.
Instead, what i do is during my ansible playbook as root i mount the nfs mount to a mountpoint (for this example, /app/myapp/myapp-nfs) and i use a bind mount when starting the container.
first make sure the nfs is properly mounted on the filesystem
# src must be accessible by nfs
- name: Make sure nfs is mounted
ansible.posix.mount:
src: nfs.ip.address.here:/shared/nfsdir
path: /app/myapp/myapp-nfs
opts: rw,sync,hard,_netdev
boot: yes
state: mounted
fstype: nfs
become: yes
second when starting the container use the available nfs as a bind mount
# src must be accessible by nfs
- name: Make sure my nfs-enabled-elite-app is started
containers.podman.podman_container:
name: nfs-enabled-elite-app
image: elite-app:latest
state: started
mounts:
- type=bind,source=/app/myapp/myapp-nfs,destination=/in/container/mount/point
so far this works.
note that you can all do this using the podman run command, just add the mount (NOT as a volume)
i really hope this gets to help people. i remain available in case you have any question just DM me.
Answered By - Quardah Answer Checked By - Willingham (WPSolving Volunteer)