'docker run -v' does not work on Windows using Docker Toolbox - windows

When running the following command from a CoreOS VM, it works as expected:
docker run --rm -v $PWD:/data composer init
It will initialize the composer.json file in the current working directory by using the Docker volume mapping as specified. The Docker container basically has the PHP tool composer installed and will run that tool inside the /data folder of the container. By using the mapping it actually applies it on the files on the host machine.
However when trying to run this command on Windows using Docker Toolbox I get the following error.
$ docker run --rm -v $PWD:/data composer --help
invalid value "C:\\Users\\Marco;C:\\Program Files\\Git\\data" for flag -v: bad mount mode specified : \Program Files\Git\data
See 'C:\ProgramData\Chocolatey\lib\docker\bin\docker.exe run --help'.
What I notice here is although I am in Git Bash when executing the command it still uses Windows paths. So then I tried following (surround with quotes):
$ "docker run --rm -v $PWD:/data composer --help"
bash: docker run --rm -v /c/Users/Marco:/data composer --help: No such file or directory
Now it is unable to find the directory.
I also tried without the $PWD variable, but this doesn't make a difference.
How do I make this work on Windows?

This should work:
$ docker run --rm -v //c/Users/Marco:/data composer --help

Try MSYS_NO_PATHCONV=1 docker run ...
Git Bash tries to convert the path for other Windows commands.

Related

The command to create a file in docker via make does not work

Docker Toolbox is installed on a Windows 8.1 PC. When I enter the command in the PhpStorm terminal, it works successfully and the file is created:
docker run --rm -v //D_DRIVE/work/7_project-manager/manager:/app --workdir=/app alpine touch .ready
If I put the same command in the Makefile and run make manager-ready
manager-ready:
docker run --rm -v //D_DRIVE/work/7_project-manager/manager:/app --workdir=/app alpine touch .ready
it works out with an error (other make commands work fine, the problem is only with this command):
D:\work\7_project-manager>make manager-ready
docker run --rm -v //D_DRIVE/work/7_project-manager/manager:/app --workdir=/app alpine touch .ready
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: the working directory 'C:/msys64/app' is invalid, it needs to be an absolute path.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
make: *** [Makefile:43: manager-ready] Error 125
How to solve the problem?

WIndows Git-bash run docker.sock

Problem
OS: Windows 10
I cannot run code bellow in git bash.
Tried using it with winpty but does not help. If I run it from cmd, it has no issues, but that is not a solution because I have a lot of commands in .sh format, so I need bash functionality. I googled the problem, but solutions are only to run from cmd.
Code below is one line
docker run -v /var/run/docker.sock:/var/run/docker.sock -d --
publish=127.0.0.1:8000:80 --network net_basic gliderlabs/logspout
Results
I expect something similar to that:
docker run -v /var/run/docker.sock:/var/run/docker.sock -d --publish=127.0.0.1:8000:80 --network net_basic gliderlabs/logspout
249a69afcdb3d80e4783c439083ec1ffd30946ccec77f2b64f66a0b41afe29e7
I get that:
docker run -v /var/run/docker.sock:/var/run/docker.sock -d --publish=127.0.0.1:8000:80 --network net_basic gliderlabs/logspout
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: Mount denied:
The source path "C:/Program Files/Git/var/run/docker.sock;C"
doesn't exist and is not known to Docker.
See 'C:/Program Files/Docker/Docker/Resources/bin/docker.exe run --help'.
Check the error. Your gitbash tried to be smart and appended path to your git at the begging : C:/Program Files/Git/var/run/docker.sock. It is a bug/feature discussed here. A quick workaround would be to mount docker.sock like this :
-v //var/run/docker.sock:/var/run/docker.sock
So your full command will be :
docker run -v //var/run/docker.sock:/var/run/docker.sock -d --publish=127.0.0.1:8000:80 --network net_basic gliderlabs/logspout
This smells to me like you didn't share your drive in Docker settings.
Right click on Docker icon in system tray and select Settings.
After that go to "Shared Drives" and select a drive you want to share with Docker daemon and click "Apply".
Docker for Windows is buggy sometimes and if that doesn't work from first, just restart Docker and it should work.

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 .

Run a docker image on Windows results in "oci runtime error: exec: "bash": executable file not found in $PATH."

I'm running Docker on Windows ("Docker Toolbox", not "Docker for Windows").
I've built an image with a rails app inside. It works properly on my Mac OS but stucks on production on Windows.
Using Docker 1.12 and docker-machine 0.8.0 on both machines.
When I create a machine and try to run the container from image, I do:
docker run -it myRepo:myTag bash
which opens me a interactive terminal on Mac OS, but Windows 7 and Windows Server 2011 are both responding with:
"Error response from daemon: oci runtime error: exec: "bash":
executable file not found in $PATH."
I use the MINGW64 shell via the Docker Quickstart Terminal but the old cmd.exe returns the same.
Can anybody help me with this issue? I've tried several hours to find a solution but there are too few answers for Windows.
Thank you in advance!
I also use Windows 7 with MINGW64. Here is what I get using nginx as example:
$docker run -it nginx bash
cannot enable tty mode on non tty input
I don't think you can open a tty using MINGW64.
You can try:
$docker run -i nginx bash
ls
bin
...
You will so no prompt or any indication you are inside the container. Just run ls and it should work inside your container.
Another option is to try to use winpty for the tty:
$ winpty docker run -it myRepo:myTag bash
root#644f59e6f818:/#
Have you tried?
$ winpty docker run -it myRepo:myTag /bin/bash
I haven't got the problem you are mentioning but I have seen it before when I was mapping volumes.
If you are mapping volumes using MINGW64, you will need to add an extra / before the local mapping. For example:
docker run -p 8080:80 -v "/$PWD":/var/share/nginx/html nginx
Let me know your findings.

Phundament under Windows - "Interactive mode is not yet supported on Windows"

I have Docker Toolbox installed under Windows 7. The Docker daemon is running inside a VM (the default behavior of Docker Toolbox).
I am trying to get Phundament running using the default tutorial.
It all works fine until I reach this command:
docker-compose run php composer install
It results in:
I've successfully attached to the running container using docker exec -it <container ID> bash but when I do a ls /app command on any of the two containers I get no files in that directory. In effect, the attempt to run composer install there fails.
I tried attaching to both containers and the result is identical.
I also noticed that behavior just recently, it's sadly a limitation of docker-compose on Windows.
For the command you mentioned you can actually run
docker-compose run -d php composer install
As general workarounds...
use docker exec -it app_php_1 bash
see also https://getcarina.com/docs/troubleshooting/troubleshooting-cannot-enable-tty-mode-on-windows/
if you don't really need an interactive shell, you could just run a command or script, like docker-compose run -d php setup.sh
Note: I need to double-check the above suggestions on a real Windows testing system.
PS: I am the author if Phundament. I've also just created an issue for this.
Please try:
winpty docker-compose run php composer install
it works for example:
winpty docker run --rm -it debian bash

Resources