Volume mounting in a Docker container
from modus@lemmy.world to selfhosted@lemmy.world on 19 Nov 23:03
https://lemmy.world/post/39039198

I’m new to Docker, but I’m trying to deploy some containers that will need to read and write to a network shared volume. I’m hoping to run things like Navidrome, Immich, and an Arr Stack. The containers are on Ubuntu and my network volume is on a qnap machine. It is discoverable from Ubuntu without issue.

Do I need to mount the shared volume in Ubuntu or can I just refer to it in the Docker Compose file?

I know I need to mention the location of the volume in the Docker Compose file, but I’m not sure how to write that. How do I include the un/pw information for the NAS?

I read about bind mounts in Docker’s documentation. Is that what I want to use? Again, how do I include the un/pw information? I’m not sure how to use the commands.

The volume path for the navidrome folder is //tiger-nas/music/music for example.

I appreciate any help.

#selfhosted

threaded - newest

roofuskit@lemmy.world on 19 Nov 23:06 next collapse

Mount it locally. Then reference the local mount in your docker command or compose file.

modus@lemmy.world on 20 Nov 00:39 next collapse

Thank you. I’ll try.

spiffpitt@lemmy.world on 20 Nov 01:07 collapse

I’m constantly seeing this advice, dispite docker supporting nfs volumes. How do you handle docker starting containers before the shares are mounted? making the docker service as a whole wait for network mounts? what about containers that dont need to wait for a network drive?

roofuskit@lemmy.world on 20 Nov 02:21 collapse

Honestly I’ve never had that issue, but if you use compose you can delay the start of a container and use the “depends-on” function to hold any other containers. But yes docker supports both NFS and SMB.

LadyMeow@lemmy.blahaj.zone on 19 Nov 23:06 next collapse

I have a similar setup, I have two servers, one with the arr stack and the other is a NAS server.

I’m my fstab I mount he network drive to say /media, then the docker containers can just have Volume: /media:/media or whatever. If you need more specifics I can look when I get home.

modus@lemmy.world on 20 Nov 00:40 collapse

Thanks. Looks good. Simple enough.

rtxn@lemmy.world on 19 Nov 23:16 next collapse

Mount the network share (fstab or mount.cifs), and pass the login using the username= and password= mount options. Then point the volume at the mount point’s path.

mattnieto.com/how-to-mount-an-smb-share-to-a-dock…

modus@lemmy.world on 20 Nov 00:39 collapse

Thank you. So the un/pw is only entered in the Ubuntu mount, not in the Docker file?

Sunny@slrpnk.net on 20 Nov 06:32 collapse

Yes ☺️

irmadlad@lemmy.world on 20 Nov 00:50 next collapse

It’s been a while so I am relying on some janky notes:

Prep:

spoiler

Create a Mount Point: sudo mkdir /mnt/myhdd Mount the HDD: sudo mount /dev/sdb1 /mnt/myhdd Verify the Mount: df -h Install Samba (if not already installed): sudo apt update sudo apt install samba Configure Samba: sudo nano /etc/samba/smb.conf Add the following at the end of the file: [MyHDD] path = /mnt/myhdd available = yes valid users = yourusername read only = no browsable = yes public = yes writable = yes Set Samba Password: sudo smbpasswd -a yourusername Restart Samba: sudo systemctl restart smbd To make the HDD mount automatically at boot, add the following line to /etc/fstab: /dev/sdb1 /mnt/myhdd ext4 defaults 0 2 make you replace /dev/sdb1 and /mnt/myhdd with your actual device and mount point.

Compose File:

spoiler

services: navidrome: image: deluan/navidrome:latest user: 0:0 # should be owner of volumes ports: - “14533:4533” restart: always environment: {} # Empty mapping - valid and fixes the error # Optional: put your config options here. Examples: # ND_LOGLEVEL: debug # ND_SCANSCHEDULE: “@every 5m” volumes: - “/docker-data/navidrome/:/data” - “/mnt/myhdd/your/path/goes/here:/music:ro” # Use forward slashes

Adjust as necessary or applicable. Maybe this will get you headed in the right direction. It’d be helpful if someone double checked my notes. I get nervous when giving instructions. LOL Also it should go without saying that you should do your due diligence verifying any code copied off the internet. Not responsible for ingrown toenails, loose stool, or blurred vision.

jaypg@lemmy.jaypg.pw on 20 Nov 01:14 next collapse

You could mount the network share on the host/Ubuntu and then reference it in your docker compose file. It works. I prefer to write the mount in the Docker compose file since it’s a bit more portable. Something like this depending on if you’re using SMB/CIFS or NFS:

services:
    some_music_app:
        image: music_app_image:latest
    container_name: music_app
    volumes:
      - smb:/some/path/smb/music
      - nfs:/some/path/nfs/music
volumes:
  smb:
    driver_opts:
      type: cifs
      o: "username=${user},password=${pass},uid=1000,gid=1000,vers=3.0"
      device: "//tiger-nas/music/music"
  nfs:
    driver: local
    driver_opts:
      type: nfs
      o: addr=tiger-nas,nolock,soft,rw,nfsvers=4
      device: ":path/to/music/music"

The ${user} and ${pass} in the smb volume definition are variables that you’ll need to have in a .env file next to your compose.yaml file. The .env file is just a normal text file with each line setting a value to a variable. Like:

user=my_username  
pass=123_abc_!@#

Then you restrict the permissions of your .env file and you can essentially take a backup of both files and use them on any server with Docker.

kowcop@aussie.zone on 20 Nov 01:28 next collapse

This is the way I do it

modus@lemmy.world on 20 Nov 01:50 collapse

I guess this is one of my big questions. If I mount it in the YAML file, do I still have to mount it in Ubuntu? Thank you for this.

GreenKnight23@lemmy.world on 20 Nov 05:48 collapse

no, it’s actually preferable that you don’t.

docker volume manager will actually mount it for you, you can see where using the “docker volume inspect {name}” command.

damnthefilibuster@lemmy.world on 20 Nov 03:01 next collapse

My network shared folders are on a windows 11 (yes, I know. It’s shit.) pc and my docker is running on Linux.

Here’s what my mounts look like -

volumes:
  plex:
    driver: local
    driver_opts:
      type: cifs
      o: username=pc_username,password=pc_password,vers=3.0,file_mode=0777,dir_mode=0777
      device: //10.0.0.3/Plex

Hope this helps.

modus@lemmy.world on 20 Nov 03:33 collapse

That helps. And it answers my question about the credentials. Thank you.

Appoxo@lemmy.dbzer0.com on 20 Nov 12:48 collapse

I tried it with NFS vol mounted in the compose but had disconnection issues.
In the end I mounted it on the host.

But I don’t know the exact issue why I had it.