Search code examples
dockerdockerfilewindowvolumedocker-volume

Adding a volume in dockerfile


I am trying to create an image of Windows with additional things. My question is whether it is possible to include a specific volume when creating the container. For example, I would like to do:

docker run --name container -v shared:c:\shared -it mcr.microsoft.com/windows/servercore:20H2-amd64 powershell

There I am accessing the shared volume, but I want to do this in the dockerfile as a command.

I want something like this after running the container:

enter image description here

Thank you for the help

I tried to use the VOLUME command but I don't know if I am doing it right or it's not for what I am trying.


Solution

  • Using VOLUME in dockerfile does not mount the volume during build, this only specifies a target where a directory can be mounted during container runtime (anonymous volume).

    Because image build and container run can happen on different machines, so having VOLUME source defined in dockerfile (buid time) does not make sense.