Docker Toolbox for Windows works by setting up a VirtualBox VM named default
using boot2docker
Linux image. Running any docker
command forwards that command to the VM (Windows Machine → Virtual Machine → Docker).
To mount local Windows folders as Docker volumes, those folders first need to be shared and mounted on the VM that is running Docker.
By default, C:\Users is shared, so mounting volumes from that location will work without any configuration.
Share your drive
You can share your drive with VirtualBox VM and be able to mount any folder from it into a Docker container.
Share your local drive with the VM
VirtualBox Manager → Settings (machine is usually named
default
) → Shared Folders → Add new shared folder:Folder Path: D:\ # Your local D: drive Folder Name: d # Name inside the VM [ ] Read-only [x] Auto-mount [x] Make Permanent
If the machine was running, it needs to be restarted with
docker-machine restart
or via VirtualBox Manager GUI.Mount the drive inside the guest machine:
sudo mount -t vboxsf -o uid=1000,gid=50 d /d
Tip: To execute this command inside VM, first run
docker-machine ssh
or open it in the VirtualBox Manager GUI.Drive
D:\
should be now available inside the VM on the path/d
.
Mounting volumes
docker run -v /d/Projects/MyProject/src:/src image # Works in CMD, Powershell
docker run -v //d/Projects/MyProject/src:/src image # Works in Bash, CMD, Powershell
Note: Depending on the shell you are using, absolute path prefix
'//'
might be required.
Note: When using
docker run -v
, provide an absolute path.
Using Docker Compose
# docker-compose.yml
...
volumes:
- ./src:/src # Valid, relative path
- D:\Projects\MyProject\src:/src # Valid, requires conversion to unix style
- /d/Projects/MyProject/src:/src # Valid, conversion not needed
...
Note: Docker Compose converts paths from Windows to Unix style if
COMPOSE_CONVERT_WINDOWS_PATHS
environment variable is set to “true” or “1”.
Troubleshooting
Invalid volume specification when using docker-compose up
ERROR: for containername Cannot create container for service servicename:
invalid volume specification: 'D:\Projects\MyProject\src:/src:rw'
Path is probably not converted to unix style. Since 1.9.0, Windows paths are not automatically converted (eg. C:\Users
to /c/Users
).
Solution: Set
COMPOSE_CONVERT_WINDOWS_PATHS
environment variable to “true” or “1”.
Invalid characters for a local volume name when using docker run
C:\Program Files\Docker Toolbox\docker.exe:
Error response from daemon:
create .;C: ".;C" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
If you intended to pass a host directory, use absolute path.
Host directory name is invalid.
Solution: You need to provide an absolute path to the folder, eg.
docker run -v /d/Projects/MyProject/src:/src image
Invalid mode when using docker run
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: invalid mode: \Program Files\Git\src.
Host directory name is invalid.
Solution: Try using
'//'
path prefix and provide an absolute path to the folder,
eg.docker run -v //d/Projects/MyProject/src:/src image
Error during connect
C:\Program Files\Docker Toolbox\docker.exe: error during connect:
Post https://192.168.99.100:2376/v1.37/containers/create: dial tcp 192.168.99.100:2376: connectex:
A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond.
Docker VM is probably stopped.
Solution: Start the Docker VM by running
docker-machine start
.