Skip to content

Latest commit

 

History

History
179 lines (106 loc) · 4.26 KB

File metadata and controls

179 lines (106 loc) · 4.26 KB

🔗 Docker Bind Mount / Binding

🔹 What is a Bind Mount?

A Bind Mount is a way to connect a folder from your computer to a folder inside a Docker container.

This means:

📁 Your Computer Folder ↔ 📦 Container Folder Both share the same files in real time.

In simple words: A Bind Mount lets a container use files directly from your own system.


🔹 Why Do We Use Bind Mounts?

Bind mounts are very useful when:

  • You are writing code and want to see changes instantly
  • You want the container to use files already on your computer
  • You are developing websites or apps
  • You need to share configuration files

👉 It is mostly used in development environments


🔹 Real Life Example

🏠 Example: Study Table & School Bag

Imagine:

  • Your study table at home = Your Computer Folder
  • Your school bag = Docker Container

Instead of copying books every day into your bag, you attach a zip line between your table and bag.

Now:

📚 If you put a book on the table → it appears in the bag 📚 If you remove a book from the bag → it disappears from the table

💡 That connection = Bind Mount

Both places show the same files.


🔹 How Bind Mount Works

  1. You choose a folder on your computer.
  2. Docker links (mounts) it into a container folder.
  3. The container reads/writes data in that folder.
  4. Changes appear on both sides instantly.

🔹 Example Without Bind Mount

If you copy website files inside a container and then delete the container:

❌ All files are lost


🔹 Example With Bind Mount

If your website files are in your system folder and mounted into container:

✅ Even if container is deleted ✅ Your files are still safe on your computer


🔹 Run a Container with Bind Mount

Syntax:

docker run -v <your-folder-path>:<container-folder> image-name

🖥 Example (Windows)

docker run -d -p 8080:80 -v C:\website:/usr/share/nginx/html nginx

Here:

Part Meaning
C:\website Folder on your computer
/usr/share/nginx/html Folder inside container
nginx Web server image

Now if you change any file inside C:\website, the website updates instantly 🚀


🐧 Example (Linux / Ubuntu)

docker run -d -p 8080:80 -v /home/user/website:/usr/share/nginx/html nginx

🔹 When to Use Bind Mount?

✅ Web development ✅ Editing code live ✅ Using config files from your system ✅ Sharing logs to your computer

❌ Not recommended for production databases (Volumes are better)


🔹 Bind Mount vs Volume

Feature Bind Mount Volume
Location Your computer folder Managed by Docker
Easy to edit files ✅ Yes ❌ Harder
Best for Development Production data
Safe if system path deleted ❌ No ✅ Yes

🔹 Check Mounts in a Running Container

docker inspect container_name

Look for the "Mounts" section.


🔹 Important Notes

⚠ If you delete files from your computer folder, they will also be deleted inside the container.

⚠ If the folder path is wrong, the container may not work properly.


🔹 Summary

✔ Bind Mount connects your system folder with a container folder ✔ Changes appear on both sides instantly ✔ Best for development work ✔ Not ideal for important production data

One-line definition:

A Bind Mount links a folder from your computer directly into a Docker container for real-time file sharing.


🧠 Author: Sharmeen Fatima
📅 Last Updated: 30 January 2026

“Learning never stops — stay curious, stay creative!”

☺️STAY HERE, STAY CONNECTED✨