Memento Lorry
Memento Lorry

Reputation: 195

docker --volume format for Windows

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 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

Upvotes: 11

Views: 6786

Answers (3)

Neeraj Sewani
Neeraj Sewani

Reputation: 4287

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))

Upvotes: 21

Arek
Arek

Reputation: 89

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

Upvotes: 2

Memento Lorry
Memento Lorry

Reputation: 195

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.

Upvotes: 6

Related Questions