简体   繁体   中英

How can I resolve the error oci runtime error: exec: no such file or directory when using docker run on Windows

When running a Docker command such as

docker run ubuntu /bin/echo 'Hello world'

used in the in the starter example docs on the Learn by Example page of the Docker docs I see the error

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: oci runtime error: exec: "C:/Program Files/Git/usr/bin/bash": stat C:/Program Files/Git/usr/bin/bash: no such file or directory.

How can I resolve this?

This error could be caused by the setup on your system including mingw (you might see this if you have installed Git for Windows with MSYS2 for example - see here for more information). The path is being converted - to stop this you can use a double slash // before the command. In this example you can use

docker run ubuntu //bin/echo 'Hello world'

(notice the double slash (//) above). If all goes well you should now see

Hello world

An complete and slightly more complex example is starting an Ubuntu interactive shell

 docker run -it -v /$(pwd)/app:/root/app ubuntu //bin/bash

Note that in my case using Git Bash I only needed one extra slash because echo $(pwd) on my machine expands to:

/c/Users/UserName/path/to/volume/mount

As another example the following can be used if zip is not available (as is the case on Windows 10 as well as Git Bash) You cannot easily zip a file for a something like an AWS Lambda function (actually there are few ways without Docker or even installing third party software if you prefer). If you want to zip the app folder under your current directory use this:

 docker run -it -v /$(pwd)/app:/root/app mydockeraccount/dockerimagewithzip //usr/bin/zip -r //root/app/test1.zip //root/app 

The mydockeraccount/dockerimageqithzip can be build by creating a Dockerfile like this:

FROM ubuntu
RUN apt-get update && apt-get install -y zip

Then run:

docker build -t mydockeraccount/dockerimagewithzip .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM