Docker Toolbox: Error response from daemon: invalid mode: /root/docker
Asked Answered
T

8

36

I am a Docker newbie and currently replicating course videos. I have to add that I only have Windows 10 Home and I am hence limited to Docker Toolbox. (At work I have W 10 Pro and use Docker itself and didnt experience the problem I am about to report).

When I run the following in the Windows Power Shell:

PS C:\Program Files\Docker Toolbox> docker run -ti -h python -v ${pwd}:/root/docker -p 9999:9999 ubuntu:latest /bin/bash

I get the following error

C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: invalid mode: /root/docker.
   See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

The problem doesnt occur in the command prompt, so it seems to be related to the Power Shell. I did not find anything in discussion boards. Any input would be appreciated.

Best Markus

Tautonym answered 26/5, 2018 at 8:9 Comment(0)
C
43

I got the same issue while using docker toolbox. Using one more '/' before your source path as well as before your target path will resolve this problem. In your case it will look like this:

docker run -ti -h python -v /${pwd}://root/docker -p 9999:9999 ubuntu:latest /bin/bash

if this doesn't work then try using absolute path with extra '/' like this:

docker run -ti -h python -v //c/path_to_application://root/docker -p 9999:9999 ubuntu:latest /bin/bash
Cockfight answered 1/11, 2018 at 7:55 Comment(1)
Thanks, it works fine also on win10 with Bash (docker quickstart terminal).Autocorrelation
B
31

The "invalid mode" error comes from parsing the third field in a volume mount, where each field is separated by a colon. In this command:

docker run -ti -h python -v ${pwd}:/root/docker -p 9999:9999 ubuntu:latest /bin/bash

The ${pwd} is going to expand to something like c:\Program Files\.... That means the volume mount will get parsed as:

  • source: C (or your current drive letter, this gets processed as a named volume rather than a host path)
  • target: /Program Files/... or wherever you happen to be running this command from.
  • mount options: /root/ which is an "invalid mode" (normal options include things like ro for a read only mount)

What's needed is a leading slash before the drive letter, and you want to remove the extra colon after the drive letter. With PowerShell, you may be forced to expand the path manually without using ${pwd}. That would look like:

docker run -ti -h python -v "/c/Program Files/...:/root/docker" -p 9999:9999 ubuntu:latest /bin/bash

If you use git bash, it has its own unique feature of turning something with a forward slash into a relative path under its install directory. To disable that, you switch to a second leading slash:

docker run -ti -h python -v "/$(pwd):/root/docker" -p 9999:9999 ubuntu:latest //bin/bash

Note in both examples, I've quoted the path in case in includes spaces.

Brittaneybrittani answered 26/4, 2020 at 12:45 Comment(0)
S
18

I suggest you to use absolute path in windows, Something like:

docker run -ti -h python -v /c/path_to_application:/root/docker -p 9999:9999 ubuntu:latest /bin/bash

Add /c/then_remaining_part_to_your_app, note that /c/ is the drive.

Screak answered 2/10, 2018 at 3:38 Comment(2)
Yes, it should, but even I see /root/docker folder, it is empty.Liaoyang
Awesome. I'm glad, it didScreak
L
15

Turned out that Docker Toolbox needs a different approach as stated in this discussion

Docker Forums: Map Windows Directory to Docker Container

As they said,

On Windows, you can not directly map Windows directory to your container. Because your containers are reside inside a VirtualBox VM. So your docker -v command actually maps the directory between the VM and the container.

So you have to do it in two steps:

Map a Windows directory to the VM through VirtualBox manager Map a directory in your container to the directory in your VM You better use the Kitematic UI to help you. It is much eaiser.

  • I first defined a shared folder on VirtualBox to the machine I use.
  • Then closed that machine and docker windows, then started docker toolbox again.
  • Then run docker-machine ssh default, and just change directory to the folder you shared (with given name). Mine was "cd mydocker", then with ls you can see the files you shared with VM.
  • And in toolbox, run docker run -it -v /mydocker:/path_in_container image_name /bin/sh
  • You should see the folder and content in /path_in_container.
Liaoyang answered 19/10, 2018 at 7:15 Comment(1)
I had to add one more '/' before virtual machine path and remove '-it'. Thanks for the detailed steps!Coccidioidomycosis
F
4

I also had the same issue with Docker and my solution was partially solved by one of the answers above that said to use one / before the PWD command.

However /${pwd} with curly braces was giving me a bad output in Git Bash, so the answer for that issue was to use /$(pwd).

The final answer for Docker was:

docker run --rm -v "/$(pwd)/function":/var/task:ro,delegated -v "/$(pwd)/layer":/opt:ro,delegated lambci/lambda:python3.8 Main.lambda_handler '{"someVar": "someValue", "var2": "value2"}'
Freewheel answered 17/2, 2021 at 22:9 Comment(0)
K
1

The other answers are super useful. Just want to add something I learned while researching this. It is regarding the POSIX-Windows file path translation that gitbash for windows does under the hood. It has to do with colons becoming semi-colons to match PATH delimiter. It is better explained here. It seems that when you do the escaping you need to match the volume mount as stated in other answers. Anyway, hopefully this also helps others.

Kan answered 4/7, 2020 at 14:8 Comment(0)
L
0

The error message you're seeing indicates that the path you're using for the Docker volume mount is not an absolute path.

To fix this, you can replace ${pwd} with the absolute path to your local directory. Here's how you can find the absolute path on Windows:

  1. Navigate to the directory you want to use for the Docker volume mount using the cd command.

  2. Type echo %cd% and press Enter. This will print the absolute path to the current directory.

  3. Now you can replace ${pwd} in the Docker run command with the absolute path you just found, surrounded by quotes.

docker run -it -h python -v "%cd%":/root/docker -p 9999:9999 ubuntu:latest /bin/bash

Log answered 12/3, 2023 at 17:25 Comment(0)
H
0

Able to run the scan by running the below command for manifest scanning:

docker run --rm -v C:/projects/abc:/test aquasec/trivy:latest --exit-code 0 --severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL --format template --template "@contrib/html.tpl" -o /test/manifest-scanning-report.html config /test/k8s_dir

This will generate a manifest-scanning-report.html under C:/projects folder.

Harlan answered 2/9, 2023 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.