Mounting host directory into container

Tested Infrastructure

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

Pre-requisite

Using custom “bind-mounts”

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

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