9

I'm trying to take a shell script we use at work to set up our development environments and re-purpose it to work on my Windows environment via Git Bash.

The way the containers are brought up in the shell script are as follows:

docker run \
--detach \
--name=server_container \
--publish 80:80 \
--volume=$PWD/var/www:/var/www \
--volume=$PWD/var/log/apache2:/var/log/apache2 \
--link=mysql_container:mysql_container \
--link=redis_container:redis_container \
web-server

When I run that as-is, it returns the following error message:

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: invalid bind mount spec "/C/Users/username/var/docker/environments/development/scripts/var/log/apache2;C:\\Program Files\\Git\\var\\log\\apache2": invalid volume specification: '/C/Users/username/var/docker/environments/development/scripts/var/log/apache2;C:\Program Files\Git\var\log\apache2': invalid mount config for type "bind": invalid mount path: '\Program Files\Git\var\log\apache2' mount path must be absolute. See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.

I did a bunch of googling and documentation reading, but I'm a little overwhelmed by Docker, and I think I got it wrong. I tried setting up the container as follows:

docker run \
--detach \
--name=server_container \
--publish 80:80 \
--volume=/c/users/username/var/www:/var/www \
--volume=/c/users/username/var/log/apache2:/var/log/apache2 \
--link=mysql_container:mysql_container \
--link=redis_container:redis_container \
web-server

It still errors out with a similar error message. If I remove the colon:/var/www it comes up, but it doesn't seem to map those directories properly, that is it doesn't know that C:\users\username\var\www = /var/www

I know I'm missing something painfully dumb here, but when I look at the documentation I just glaze over. Any help would be greatly appreciated.

Noam Yizraeli
  • 4,446
  • 18
  • 35
Memento Lorry
  • 165
  • 1
  • 6

3 Answers3

11

For people using Docker on Windows 10, an extra / has to be included in the path:

docker run -it -v //c/Users/path/on/host:/app/path/in/docker/container command

(notice an extra / near c)

If you are using Git Bash and using pwd then use an extra / there as well:

docker run -p 3000:3000 -v /app/node_modules -v /$(pwd):/app 09b10e9fda85`

(notice / before $(pwd))

Pedro A
  • 3,989
  • 3
  • 32
  • 56
Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55
5

Well, I answered my own question moments after I posted it.

This is the correct format.

docker run \
--detach \
--name=server_container \
--publish 80:80 \
--volume=//c/users/username/var/www://var/www \
--volume=//c/users/username/var/log/apache2://var/log/apache2 \
--link=mysql_container:mysql_container \
--link=redis_container:redis_container \
web-server

Should have kept googling a few minutes longer.

Memento Lorry
  • 165
  • 1
  • 6
  • Are you able to access the files now? I tried using this same method but not able to see the windows files. `docker run -v //c/temp/:/test alpine ls test` temp.txt `ls /c/temp` 'Encoding Time.csv' http1/ netstat.txt Projects/ selfcheck.json Stack/ UninstalItems.log It appears the docker container has it's own separate and independent copy of the c:\temp directory – Donald S Jun 26 '20 at 03:28
2

If you want to make the path relative, you can use pwd and variables. For example:

CURRENT_DIR=$(pwd)    
docker run -v /"$CURRENT_DIR"/../../test/:/test alpine ls test
Arek
  • 89
  • 4