Docker Toolbox在PowerShell挂载卷报错:invalid mode: /root/docker
Hey there! I totally get your frustration—switching between Windows Pro (with native Docker) and Home (stuck with Docker Toolbox) can throw some weird curveballs. Let's break down why this error is happening and fix it.
Why the Error Happens
Docker Toolbox runs Docker inside a VirtualBox virtual machine, which uses a Linux-style filesystem. When you use ${pwd} in PowerShell, it outputs a Windows-style path like C:\Program Files\Docker Toolbox. The Docker daemon (running in the VM) doesn't recognize this format, hence the invalid mode: /root/docker error.
On the other hand, CMD works because Docker Toolbox's CMD environment automatically converts Windows paths to the Linux-style /mnt/c/... format that the VM understands when you use %cd%.
Solutions to Try
Here are a few straightforward fixes to get your command working in PowerShell:
1. Manually Convert the Path
Replace your Windows path with a Linux-compatible format for the VM. For example, C:\Program Files\Docker Toolbox becomes /mnt/c/Program Files/Docker Toolbox. Wrap the path in quotes to handle spaces:
docker run -ti -h python -v "/mnt/c/Program Files/Docker Toolbox":/root/docker -p 9999:9999 ubuntu:latest /bin/bash
2. Auto-Convert Path with PowerShell
Use PowerShell string replacement to automatically turn your current directory into the correct format. First define the converted path, then run the Docker command:
# Convert Windows path to Docker Toolbox-compatible Linux path $dockerMountPath = $(Get-Location).Path -replace '^([A-Z]):', '/mnt/$1' -replace '\\', '/' # Run the Docker command with the converted path docker run -ti -h python -v "${dockerMountPath}":/root/docker -p 9999:9999 ubuntu:latest /bin/bash
3. Use WSL Path Conversion (If You Have WSL Enabled)
If you have Windows Subsystem for Linux installed, the wslpath tool can handle the conversion for you in one line:
docker run -ti -h python -v "$(wslpath -a ${pwd})":/root/docker -p 9999:9999 ubuntu:latest /bin/bash
Any of these should get your volume mount working correctly in PowerShell. Let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者Markus Knopfler

