How to mount a local directory in docker container

Recently i had to use a video manipulation software in docker container. But the problem i faced is, the video files i had to enter into the software are too large. The smallest one of them is like 12 GB. This was a local system, converting some local file was the only purpose of this software. So easiest solution was to use the volume mount. Docker run command’s volume(-v) switch will help to mount a local folder inside our container.

So i put all my video in a directory called videos in the same directory as my Dockerfile. Lets says there is one video called “sky_video.mp4”

reaz@reazmac> ls 
Dockerfile  videos/

My docker image is called “rainbow” .So I start my container with the following command:

docker run -it -v "$(pwd)/videos":/home/reaz/videos rainbow

Here,  the trick is on this bit


. Normally we use <pre> . </pre> to mention the present directory, but docker does not interpret it well. so we use


Now , when my container starts, I can go into the /home/reaz/videos directory. Here i can see my “sky_video.mp4” is there.

/ # cd /home/reaz/videos ; ls

Now i can put all my videos in my local computer’s videos folder, and those will be rightly available inside my container to be used by the software.

Leave a comment