3

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?

G3tinmybelly
  • 1,777
  • 2
  • 15
  • 18

1 Answers1

2

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%
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I need to use git bash to run shell scripts unfortunately... and when I do your "sh -c" thing I get this as an error "sh: 1: C:/Program: not found" – G3tinmybelly Nov 16 '17 at 01:09
  • @G3tinmybelly Can you try with double-quotes instead simple quotes? – VonC Nov 16 '17 at 08:19