Skip to main content

📚 Mounting a Network Share for Docker on Debian

 

🧭 Overview

This guide shows how to mount a CIFS/SMB network share on a Debian-based system and use it as a volume in Docker Compose. Useful when your Docker container needs access to shared files hosted on another machine (e.g., a NAS, Windows PC, or another Linux box).


🛠️ Step 1: Install CIFS Utilities

sudo apt update
sudo apt install cifs-utils

📂 Step 2: Create a Mount Point

sudo mkdir -p /mnt/downloads

🔐 Step 3: Mount the Share

sudo mount -t cifs //LORGAR/Downloads /mnt/downloads -o username=slitzer,password=blink182,vers=3.0

Replace:

  • //LORGAR/Downloads — with the remote share path
  • username and password — with valid credentials
  • vers=3.0 — adjust based on your SMB version (2.0, 3.1.1, etc.)

💾 Optional: Persistent Mount via fstab

Edit /etc/fstab:

//LORGAR/Downloads /mnt/downloads cifs username=slitzer,password=blink182,vers=3.0,uid=1000,gid=1000 0 0

Using a secure credentials file:

# /root/.smbcredentials
username=slitzer
password=blink182

Then in /etc/fstab:

//LORGAR/Downloads /mnt/downloads cifs credentials=/root/.smbcredentials,vers=3.0,uid=1000,gid=1000 0 0

Don't forget: chmod 600 /root/.smbcredentials


🐳 Step 4: Use in Docker Compose

Update your docker-compose.yml:

version: '3'
services:
  myapp:
    image: myapp/image
    volumes:
      - /mnt/downloads:/app/shared

This maps the mounted network share inside the container.


🔍 Troubleshooting

  • Check if mounted: mount | grep downloads or df -h
  • Check permissions: ls -la /mnt/downloads
  • Logs: dmesg, journalctl -xe

✅ TL;DR

sudo apt install cifs-utils
sudo mkdir -p /mnt/downloads
sudo mount -t cifs //REMOTE_HOST/Share /mnt/downloads -o username=...,password=...,vers=3.0

Then reference /mnt/downloads in your Docker volumes.


🧠 Pro Tip: Avoid hardcoding passwords by using credential files, especially for systems in production.