Skip to content

Latest commit

 

History

History
106 lines (69 loc) · 1.89 KB

bind-mounts.md

File metadata and controls

106 lines (69 loc) · 1.89 KB

Mounting host directory into container

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

  • Create an account with DockerHub
  • Open PWD Platform on your browser
  • Click on "Add New Node"

Using custom "bind-mounts"

In some cases, you want a specific directory on the host to be mapped inside the container:

  • You want to manage storage and snapshots yourself.

    (With LVM, or a SAN, or ZFS, or anything else!)

  • You have a separate disk with better performance (SSD) or resiliency (EBS) than the system disk, and you want to put important data on that disk.

  • You want to share your source directory between your host (where the source gets edited) and the container (where it is compiled or executed).

Wait, we already met the last use-case in our example development workflow! Nice.

$ docker run -d -v /path/on/the/host:/path/in/container image ...

Execute the following commands:

Creating "test" directory

mkdir test

Cleaning the system

docker system prune

Cleaning the Volumes

docker volume prune

Listing out the Volumes

docker volume ls

Mounting host directory into container

docker run --env MESSAGE="GOOD Afternoon" --env FILENAME=afternoon_message\
 --mount type=bind,source="$(pwd)"/test,target=/data \
 sagarj/volume_test:1

Verifying the Docker Volume

docker volume ls

Verifying the File placed in container sitting on Host console

cd ./test
ls
cat afternoon_message