Mounting host drives in Docker for Windows with Git Bash

Posted on Posted in Docker

When try­ing to share a local dri­ve with my dock­er con­tain­ers using Dock­er for Win­dows in my Git Bash shell, I kept get­ting errors about invalid mount specs. Even just fol­low­ing along with the basic exam­ple pro­vid­ed in the Dock­er for Win­dows dia­log for shar­ing dri­ves fails:

$ dock­er run --rm -v c:/Users:/data alpine ls /data
dock­er: Error response from dae­mon: invalid bind mount spec "c;C:\\Program Files\\Git\\Users;C:\\Program Files\\Git\\data": invalid mode: \Pro­gram Files\Git\data.

This turns out to be an issue with Git Bash (and MSYS in gen­er­al) attempt­ing to resolve and expand our paths before hand­ing them off to dock­er. Escap­ing the for­ward-slash­es with an extra for­ward-slash resolves this issue:

$ dock­er run --rm -v c://Users://data alpine ls //data
All Users
Default User

This is not an issue from with­in Pow­er­Shell or the Com­mand Prompt, so stick with one of those when work­ing with dock­er or remem­ber to escape your slash­es when pass­ing them into the dock­er command.

Leave a Reply

Your email address will not be published. Required fields are marked *