Why is my "docker-compose run" not working properly on windows?

Viewed 3083

So I am running a script that calls:

docker-compose run --rm web sh /data/bin/install_test_db.sh

and it seems to work fine when running it on ubuntu but when I run it on Windows using Git Bash I get this error:

sh: 0: Can't open C:/Program Files/Git/data/bin/install_test_db.sh

It seems to be trying to run the script on my machine and not the actual container from which I am trying to call it from.

Any ideas on why this is happening?

1 Answers

First, try passing a command to your sh shell:

docker-compose run --rm web sh -c "/data/bin/install_test_db.sh" 

Or:

docker-compose run --rm web "sh -c /data/bin/install_test_db.sh" 

That will avoid your host shell (the git bash) to interpret an absolute path (starting with '/') as one from the Git installation path.

That will keep /data/... as an argument to be passed to the shell executed in the container.


Note: If you are using Docker for Windows (meaning not VirtualBox, but HyperV), you don't need git bash at all.

Try the same command from a regular CMD (with docker.exe in your %PATH%, which Docker for Windows set for you)

vonc@VONCAVN7 C:\Users\vonc
> where docker
C:\Program Files\Docker\Docker\Resources\bin\docker.exe

If you need Linux-like commands from that same CMD session, then yes, add git paths:

set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
Related