I’m experiencing an issue using Docker Engine on Windows Server 2019 with Linux Kit which does not exist on either Docker for Linux or Docker Desktop for Windows 10.
The scenario is the following – I have an image MyLinuxImage whose execution depends on a root level file /file.txt. Now on both Docker Desktop and Docker Linux, this is an easy thing to configure – simply bind a file onto that file using the argument
-v C:\path\myfile.txt:/file.txt . However, on Docker Engine on Windows server, this mount fails with the message:
docker: Error response from daemon: invalid volume specification: C:\path\myfile.txt:file.txt:/file.txt': invalid mount config for type "bind": source path must be a directory.
I’ve additionally tried several configurations using the
--mount flag, and bind mounts using single file fail using this syntax as well. I’ve experienced this issue on both Docker engine 18 (18.06) and 19 (19.03.5).
Additionally, trying to mount a directory at the root level fails because the root level cannot have a directory mounted to it.
Unfortunately, this image in question is not a home baked one for which I can just move the file location.
So I’m wondering the following
- Are there any options I may be missing to resolve this issue?
- Is there a tracking bug for this issue already that anyone is aware of?
Update: Answer found
Okay, I found a solution. While bind mounting does not work for single files using docker engine on windows, it can be worked around by first creating the container, then copying the file into the container, then starting that container.
docker container create myimage docker container cp myfile.txt <id>:/file.txt docker start <id>