Folder and volume mapping on Windows docker containers

Things I've learnt

Mapping folder host to container.

In this example I will map a directory c:\foo from my host machine to c:\bar on the target container. Notice that I can read/write files in that directory from both the host and the container.


Host Machine

cd c:\
mkdir foo
docker run -it -v c:\foo:c:\bar microsoft/windowsservercore

Windows Container

cd c:\bar
echo helloworld >> myfile.txt
type myfile.txt

Mapping a volume host to container

In this example I will be mapping a volume that I will create named myvolume by running docker volume create myvolume. This will create a volume that is mounted on my local disk at c:\ProgramData\Docker\volumes\myvolume\_data which is found by inspecting the volume created by running docker volume inspect myvolume.

Host

cd c:\
docker volume ls
docker volume create myvolume
docker volume ls
docker volume inspect myvolume

docker volume inspect myvolume

[
    {
        "CreatedAt": "2017-11-03T19:07:05+11:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "C:\\ProgramData\\Docker\\volumes\\myvolume\\_data",
        "Name": "myvolume",
        "Options": {},
        "Scope": "local"
    }
]

Host

docker run -it -v myvolume:c:\foobar microsoft/windowsservercore

Container

cd foobar
dir foobar
echo helloworld >> myfile.txt
type myfile.txt

Host

cd c:\ProgramData\Docker\volumes\myvolume\_data
dir
type myfile.txt