📚 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:


💾 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


✅ 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.


Revision #1
Created 2025-06-01 10:33:06 UTC by Slitzer
Updated 2025-06-01 10:33:43 UTC by Slitzer