'Use a (virtual) hard drive in windows docker image

I am trying to create a base docker image for a windows application. I know that windows images have their drawbacks and their pitfalls but the application won't run in a linux environment. It is necessary to have some data on the G: drive and that is where I can't seem to get it to work. I don't need to map the G: volume to my hard drive, I just need to install some stuff there. Here is my Dockerfile:

FROM mcr.microsoft.com/windows/servercore:20H2

Volume "G:"

RUN powershell wget http://some.url/file.zip -OutFile G:\file.zip
RUN tar -xf G:\file.zip -C G:

But the docker build fails on the last line because the file does not show up on the G: drive. I tried downloading the file to the C: drive and then extract it to G: and I also tried to extract it to C: and then copy it to G: but none have worked. The G: drive is always empty. When I exec into the container and run the commands from the Dockerfile it works as expected. Only when I run docker build the G: drive is completely ignored. What could I be doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source