Saturday, May 18, 2019

Mapping docker volume

Starting to learn docker and encountered some issues when mounting volumes to my container. Had to tweak the commands using a mix of what I can find online as the commands I used online couldn't work for my system which is a windows 10.


Steps you need to do if you are in the same situation as me. In my case, I wasn't able to find my volume as well even following the path after inspecting the volume.


1. Enable drive sharing through the settings in the whale icon at the bottom right corner.

2. Use the following command to map host folder to container folder of your choice
(For some reason I have to also attach my container again otherwise it doesn't work.)

$ docker run -d -it --name someContainer \
             -v "D:/projects/testData":/tmp someImage
$ winpty docker attach someContainer  
$ # ls tmp

(Whatever files you have put in testData folder should show up here and vice versa)

Notes:
- winpty is required in windows otherwise it can't run. Anyway you will be prompted. 
- perhaps there is a better way or i need to do something about my configs, but for now this works for me.