Docker Course
Docker
/
Intermediate

Bind Mounts

Definition

A storage option where a specific, user-defined file or directory on the Host machine is directly mounted into a container. The container accesses the exact same physical files the Host sees.

Explain Like I'm New

A two-way window. You glue a folder on your MacBook directly to a folder inside the container. If you edit a file on your MacBook, the container instantly sees the change. If the container deletes a file, it is deleted from your MacBook.

Real World Example

Live-reloading in local development. You run a React app container and bind mount your laptop's `src` folder using `-v $(pwd)/src:/app/src`. When you hit 'Save' in VS Code on your laptop, the React server inside the container instantly recompiles.

Common Use Cases

  • •Local code development
  • •Sharing configuration files

Interview Questions

basic

  • Which storage type requires you to specify an exact, absolute file path on your host machine: Volumes or Bind Mounts?

intermediate

  • Why are Bind Mounts considered a security risk in production environments?

Flash Cards

Question

Which requires a path?

Click to reveal answer
Answer

Bind Mounts. (e.g., `-v /Users/steve/desktop/app:/app`).

Question

Why a security risk?

Click to reveal answer
Answer

Because a container has absolute access to whatever you mount. If a developer accidentally mounts the host's root directory (`-v /:/host`), a hacker breaching the container could literally delete the host server's operating system.