What is a bind mount in Docker?

0182

A bind mount in Docker is a way to link a file or directory from the host machine's filesystem to a container. Unlike Docker volumes, which are managed by Docker and stored in a specific location, bind mounts allow you to specify an exact path on the host. This means that the container can access and modify files directly on the host's filesystem.

Key Points:

  • Full Path Reference: A bind mount uses the full path of the file or directory on the host.
  • Limited Functionality: Bind mounts have less functionality compared to Docker volumes.
  • Host Dependency: They rely on the host's filesystem structure.
  • Direct Changes: Processes running in the container can change the host filesystem.

Syntax:

The --mount flag is used for bind mounts with the following syntax:

docker run -it --mount type=bind,source=<host_path>,target=<container_path> <image_name>

Example:

docker run -it --name busybox --mount type=bind,source="$(pwd)"/data,target=/data busybox sh

In this example, the data directory from the current host directory is mounted to /data in the container.

0 Comments

no data
Be the first to share your comment!