15 KiB
15 KiB
📊 Docker Bind Mounts - Visual Guide
Architecture Diagram
┌─────────────────────────────────────────────────────────────────┐
│ Windows Server Host │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ D:\AppData\ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌──────────────┐ ┌────────────┐ │ │
│ │ │ Faces\ │ │ Storage\ │ │ Logs\ │ │ │
│ │ │ (Face DB) │ │ (Uploads) │ │ (App Logs) │ │ │
│ │ └──────┬──────┘ └──────┬───────┘ └─────┬──────┘ │ │
│ │ │ │ │ │ │
│ └─────────┼─────────────────┼─────────────────┼────────────┘ │
│ │ │ │ │
│ Bind │ Bind │ Bind │ │
│ Mount │ Mount │ Mount │ │
│ │ │ │ │
│ ┌─────────┼─────────────────┼─────────────────┼────────────┐ │
│ │ ↓ ↓ ↓ │ │
│ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │
│ │ ┃ Docker Container: gozareshgir-servicehost ┃ │ │
│ │ ┃ ┃ │ │
│ │ ┃ ┌─────────┐ ┌───────────┐ ┌──────────┐ ┃ │ │
│ │ ┃ │ /app/ │ │ /app/ │ │ /app/ │ ┃ │ │
│ │ ┃ │ Faces/ │ │ Storage/ │ │ Logs/ │ ┃ │ │
│ │ ┃ └─────────┘ └───────────┘ └──────────┘ ┃ │ │
│ │ ┃ ┃ │ │
│ │ ┃ ┌────────────────────────────────────────┐ ┃ │ │
│ │ ┃ │ ASP.NET Core Application │ ┃ │ │
│ │ ┃ │ - Reads/Writes to /app/Faces │ ┃ │ │
│ │ ┃ │ - Reads/Writes to /app/Storage │ ┃ │ │
│ │ ┃ │ - Writes logs to /app/Logs │ ┃ │ │
│ │ ┃ └────────────────────────────────────────┘ ┃ │ │
│ │ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ │ │
│ │ │ │
│ │ Ports: 5003 (HTTP) → 80, 5004 (HTTPS) → 443 │ │
│ └───────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Data Flow Example
Scenario 1: User uploads a file via the web application
User → HTTPS (5004) → Container (:443) → ASP.NET Core
↓
Writes to /app/Storage/file.pdf
↓
[Bind Mount - Real-time sync]
↓
D:\AppData\Storage\file.pdf
✅ File persists on Windows host immediately
Scenario 2: Application logs an event
ASP.NET Core → Serilog → Writes to /app/Logs/gozareshgir_log.txt
↓
[Bind Mount - Real-time sync]
↓
D:\AppData\Logs\gozareshgir_log.txt
✅ Logs can be viewed directly from Windows host
Scenario 3: Administrator adds a face image manually
Admin → Copies file to D:\AppData\Faces\user123.jpg
↓
[Bind Mount - Real-time sync]
↓
/app/Faces/user123.jpg
↓
ASP.NET Core sees file immediately
✅ No container restart needed
Container Lifecycle vs Data Persistence
┌────────────────────────────────────────────────────────────┐
│ Container Lifecycle │
├────────────────────────────────────────────────────────────┤
│ │
│ docker-compose up -d │
│ ↓ │
│ Container Running │
│ │ │
│ ├─ /app/Faces ←──────┐ │
│ ├─ /app/Storage ←──────┼─ Bind Mounts (always active) │
│ ├─ /app/Logs ←──────┘ │
│ │ │
│ docker-compose down │
│ ↓ │
│ Container Removed │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ ✅ DATA STILL EXISTS ON HOST │ │
│ │ D:\AppData\Faces\ │ │
│ │ D:\AppData\Storage\ │ │
│ │ D:\AppData\Logs\ │ │
│ └──────────────────────────────────────────┘ │
│ │
│ docker-compose up -d │
│ ↓ │
│ Container Running (new instance) │
│ │ │
│ ├─ /app/Faces ←──────┐ │
│ ├─ /app/Storage ←──────┼─ Bind Mounts (reconnected) │
│ ├─ /app/Logs ←──────┘ │
│ │ │
│ ✅ ALL PREVIOUS DATA IMMEDIATELY AVAILABLE │
│ │
└────────────────────────────────────────────────────────────┘
Bind Mounts vs Docker Volumes
| Feature | Bind Mounts (Current) | Docker Volumes (Old) |
|---|---|---|
| Location | D:\AppData\* |
Hidden Docker storage |
| Direct access from host | ✅ Yes | ❌ Difficult |
| Windows Explorer | ✅ Yes | ❌ No |
| Backup with robocopy | ✅ Yes | ❌ Requires export |
| Visible path on host | ✅ Yes | ❌ Obscured |
| Production-safe | ✅ Yes | ⚠️ Less transparent |
| Performance on Windows | ✅ Good | ✅ Good |
| Migration to another server | ✅ Easy (copy folder) | ⚠️ Export/import |
File Operations - Who Can Access?
┌───────────────────────────────────────────────────────────┐
│ File Access Matrix │
├──────────────────────┬────────────────┬───────────────────┤
│ │ Container │ Windows Host │
├──────────────────────┼────────────────┼───────────────────┤
│ Read files │ ✅ Yes │ ✅ Yes │
│ Write files │ ✅ Yes │ ✅ Yes │
│ Delete files │ ✅ Yes │ ✅ Yes │
│ Create directories │ ✅ Yes │ ✅ Yes │
│ Rename files │ ✅ Yes │ ✅ Yes │
│ Move files │ ✅ Yes │ ✅ Yes │
│ Real-time sync │ ✅ Instant │ ✅ Instant │
│ File locking │ ✅ Shared │ ✅ Shared │
└──────────────────────┴────────────────┴───────────────────┘
Permissions Flow
Windows Host
↓
D:\AppData\Faces (NTFS Permissions: Everyone - Full Control)
↓
Bind Mount (Docker translates permissions)
↓
/app/Faces (Container sees as writable)
↓
ASP.NET Core (Can read/write as app user)
Storage Usage Monitoring
┌─────────────────────────────────────────────────────┐
│ Recommended Monitoring │
├─────────────────────────────────────────────────────┤
│ │
│ Weekly: Check disk space │
│ Get-PSDrive D | Select Used, Free │
│ │
│ Monthly: Analyze folder sizes │
│ Get-ChildItem D:\AppData -Directory | │
│ ForEach { $_ | Add-Member -NotePropertyName │
│ Size -NotePropertyValue (Get-ChildItem $_. │
│ FullName -Recurse | Measure-Object -Property │
│ Length -Sum).Sum -PassThru } | Select Name, │
│ @{Name="SizeGB";Expression={[math]::Round( │
│ $_.Size/1GB,2)}} │
│ │
│ Quarterly: Review and archive old files │
│ Consider moving files older than 6 months │
│ │
└─────────────────────────────────────────────────────┘
Quick Command Reference
Check what's mounted
docker inspect gozareshgir-servicehost --format='{{range .Mounts}}{{.Source}} → {{.Destination}}{{println}}{{end}}'
Expected output:
D:\AppData\Faces → /app/Faces
D:\AppData\Storage → /app/Storage
D:\AppData\Logs → /app/Logs
Test bi-directional sync
# From container to host
docker exec gozareshgir-servicehost sh -c "echo 'from container' > /app/Storage/test1.txt"
Get-Content D:\AppData\Storage\test1.txt
# From host to container
"from host" | Out-File D:\AppData\Storage\test2.txt
docker exec gozareshgir-servicehost cat /app/Storage/test2.txt
# Cleanup
Remove-Item D:\AppData\Storage\test*.txt
Monitor real-time file activity
# Watch for file changes in Storage directory
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "D:\AppData\Storage"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
Register-ObjectEvent $watcher "Created" -Action {
Write-Host "File created: $($Event.SourceEventArgs.FullPath)" -ForegroundColor Green
}
Troubleshooting Flowchart
Container not seeing files?
↓
Check: Do directories exist on host?
├─ No → Run: setup-bind-mounts.ps1
└─ Yes → Continue
↓
Check: Are bind mounts configured?
├─ No → Fix docker-compose.yml
└─ Yes → Continue
↓
Check: Does container have write permissions?
├─ No → Run: icacls commands
└─ Yes → Continue
↓
Check: Is container running?
├─ No → docker-compose up -d
└─ Yes → Check application logs
For more details, see:
CONFIGURATION_SUMMARY.md- Complete setup guideDOCKER_BIND_MOUNTS_SETUP.md- Full documentationQUICK_REFERENCE.md- Command reference