Search code examples
dockerdocker-for-windowsdocker-volume

Mounting single file in docker running on windows server 2019 (error: Invalid volume specification...)


I am trying to run multiple Linux containers in Docker EE running on Windows server 2019. Everything is going well until I mount a single file to a container, like:

VOLUME:
 - c:\xxx\yyy.xml:/app/yyy.xml

When I spun up an instance I receive an error:

ERROR: for xxx Cannot create container for service s1: invalid volume specification: 'C:\Users\xxx\yyy.xml:/app/yyy.xml' invalid mount config for type "bind": source path must be a directory

Mounting a single file is possible in running Docker CE (on windows).

Is there a way get this working without too many custom workarounds?


Solution

  • Sadly no - Here is the link to the relevant issue on github.

    https://github.com/moby/moby/issues/30555

    The gist of it...

    thaJeztah wrote

    Correct, bind-mounting files is not possible on Windows. On Linux, there's also quite some pitfalls though, so mounting a directory is preferred in many situations.

    However, Drewster727 pointed out the following

    For some context on my situtation--

    We're running apps in the legacy .NET framework world (/sad-face) -- we have .config files mixed in with our application binaries. We don't want to build environment-specific containers, so of course, we try to share config files that have been transformed per environment directly inside the container to the location our application expects them.

    In case it helps anyone, I have a simple entrypoint.ps1 script hack to get around this issue for now. Share a directory to c:\conf with config files in it, the script will copy them into the app context folder on start:

    if(Test-Path c:\conf){ Copy-Item -path c:\conf*.* -Recurse -Destination . -Force }