Beginner question: volume mapping to network mounted path

Hello. I'm trying to figure out a weird issue and could use some advice. On my ubuntu server, I have a nas mounted to the path: '/nas/files', and a docker container with a volume mapping to -v '/nas/files:/files' in the docker config.

​

This has been working fine for a long time, but recently I noticed the container was not writing files to the nas as expected, but also wasn't reporting any errors. As I investigated, I could see the share was properly mounted in the hostos, but when a exec-ed into the container, the /files path had different files within it. I initially thought the volume map was broken or maybe there was a permissions issue, but couldn't find an obvious issue. However, when I unmounted /nas/files in the host os, I discovered that the container was writing the host fs underneath that mount -- all the files in the container where in the native /nas/files folder underneath the mount.

​

My theory is the docker container was spun up before the filesystem mount was established, and then doesn't update to recognize the mountpoint after it is spun up. Does that sound right? Regardless, does anyone have advice on how to avoid this problem in the future?

​

Thanks!

Posted Sep 16, 2021, 4:26 PM UTC · edited

14
Routine_Part_6503•

Is the NAS using NFS or Samba (SMB/Windows)?

If NFS, get Docker to handle the NFS mounting. Here is a Compose volume snippet:

volumes:
  nfs_movies:
    driver: local
    driver_opts:
      type: nfs
      o: "addr=10.0.0.10,soft,rw"
      device: ":/export/storage/media/movies"
1
XboxSlackerOP•

It’s SMB. I looked at mounting a volume but how do you map a sub directory of a share, ie: if he smb share is “/nas/app” and I need to map the “data” folder in that share to the docker path “/config”, I wasn’t able to find a way to do that with volumes. Thanks for your help.

1
Routine_Part_6503•

You'll have to specify each child directory as a separate mount.

So, you'd map /nas/app/data to /config

In NFS, it would look like this:

volumes:
  nfs_app_data:
    driver: local
    driver_opts:
      type: nfs
      o: "addr=<nas-ip-address>,soft,rw"
      device: ":/app/data"

And in your service definition:

volumes:
  - nfs_app_data:/config

Alternatively, you can modify the Docker systemd unit to be dependent on the NFS mount unit.

1
XboxSlackerOP•

I don't think you can share SMB subdirectories in the same way as you can in NFS (I could be wrong about that though). Perhaps I can share these targets using nfs instead, I'll spend some time on that. Thanks again.

1