When I run docker run -v "hostpath:/absolute/path/to/containerfile" ... , Windows asks me for permission to share the file at hostpath.
The problem I have is, I’m running many such docker run commands from a Python script, each one mounting a single Python NamedTemporaryFile, and Windows seems to be asking me every time a new file path (which is different for each NamedTemporaryFile) is shared. Is there a way to automatically allow sharing?
Windows containers on Windows or Linux containers on Windows? Which version of Windows? I don’t remember any case when Docker Desktop needed additional permissions on Windows 11 with the WSL2 backend and I don’t know about the HyperV backend. Where is the hostpath? In your user profile folder? Or Somehwre where you would need Administrator user on Windows?
I’m using Ubuntu containers on Windows 10 Pro with Hyper-V backend. I forget why I chose not to use the WSL2 backend, as I do have WSL2 installed. I’d guess it’s due to recommendations like this one (I use several VM programs as well, such as VirtualBox and VMWare).
The hostpath is something like %LOCALAPPDATA%\Temp\tmpx3xt96zd.sh (with a different file name every time), although I don’t think Python guarantees the temp directory used will necessarily be the same on all Windows systems.
Open Docker Desktop’s settings, go to Resources » File Sharing and make sure local app data is shared. Since this setting is not available with the WSL2 backend, I can’t check what the default shared folders are. WSL2 makes the whole Windows filesystem available, so you don’t have to add shared folders to Docker Desktop. I would expect the behavior you experience when the parent folder is not shared and (maybe) Docker Desktop tries to ask for access the individual files every time.
Yup, that seems to have done the trick. I removed all the individual files that appeared in Resources → File Sharing and added a few directories to be shared (including AppData). The docker commands are now running without asking me for sharing permissions.