S S S S - 4 months ago 84
Linux Question

Docker can't mount folder on windows

I cant mount folder on docker on windows. I'm using this repo https://github.com/LaraDock/laradock . In

docker-compose.yml
line 23 there is folders mapping

application:
build: ./application
volumes:
- ../:/var/www/laravel


In virtualbox folder
D:\VM
is shared. When I start container and list files there is just
laradock
folder but i have whole laravel installation in that folder that should be but isn't listed.

username@pc MINGW64 /d/VM/zemke2/laradock (master)
$ docker-compose up -d nginx mysql
Starting laradock_application_1
Starting laradock_data_1
Starting laradock_workspace_1
Starting laradock_php-fpm_1
Starting laradock_nginx_1
Starting laradock_mysql_1

username@pc MINGW64 /d/VM/zemke2/laradock (master)
$ docker exec -it laradock_workspace_1 bash
root@c9dbb37ace74:/var/www/laravel# ls
laradock


When i try to mount from inside machine I get permission denied.

root@c9dbb37ace74:/var/www/laravel# mount --bind /d/VM/zemke2/laradock /var/www/laravel
mount: permission denied
root@c9dbb37ace74:/var/www/laravel# sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) VM /var/www/laravel
mount: permission denied
root@c9dbb37ace74:/var/www/laravel#


When i try to bind from docker it is silent, but folder isn't mounted, files aren't listed.

username@pc MINGW64 /d/VM/zemke2/laradock (master)
$ docker run --privileged=true -it -v '//d/VM/zemke2/laradock:/var/www/laravel' laradock_application bash
root@01dff4894074:/var/www/laravel# ls
logs


Here is debug info for container that defines volume maping

username@pc MINGW64 /d/VM/zemke2/laradock (master)
$ docker inspect laradock_application
[
{
"Id": "sha256:edc4295d69f048a5ce31bdfb86fbe2132b4a3c070377028efabaed3f82235dfd",
"RepoTags": [
"laradock_application:latest"
],
"RepoDigests": [],
"Parent": "sha256:44f94094c21c3541793d77ae0635bce470a8ee3bc6af4e9d3e902530d373e62b",
"Comment": "",
"Created": "2016-05-22T22:30:28.379420591Z",
"Container": "a990cb7f02784411fce8969a6926ab39dcba1f59ad99f055b77ba8eb9b954c0a",
"ContainerConfig": {
"Hostname": "f416997e8b71",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) CMD [\"true\"]"
],
"Image": "sha256:44f94094c21c3541793d77ae0635bce470a8ee3bc6af4e9d3e902530d373e62b",
"Volumes": null,
"WorkingDir": "/var/www/laravel",
"Entrypoint": null,
"OnBuild": [],
"Labels": {}
},
"DockerVersion": "1.11.1",
"Author": "Mahmoud Zalt \u003cmahmoud@zalt.me\u003e",
"Config": {
"Hostname": "f416997e8b71",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"true"
],
"Image": "sha256:44f94094c21c3541793d77ae0635bce470a8ee3bc6af4e9d3e902530d373e62b",
"Volumes": null,
"WorkingDir": "/var/www/laravel",
"Entrypoint": null,
"OnBuild": [],
"Labels": {}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 125093399,
"VirtualSize": 125093399,
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:6eb35183d3b8bb6aee54874076fb1ad77b5259c93b330986b0cbcaa44cbbbc00",
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
"sha256:60e06fa5d2311255186d98d3cd5709c4f5f08a24a356f468beebb19749acbd10"
]
}
}
]

Answer

When using Docker Toolbox, it is a two step process to mount a folder to a container. On Windows/OS X, Docker runs inside a Virtualbox VM. First, you need to mount your Windows/OS X folder to Virtualbox. Second, you can then mount the virtualbox folder to Docker using volumes. Docker does not have access to your Windows/OS X folders except the User folder (which is because the Virtualbox VM mounts that folder to the VM by default)

If you mounted your D:/VM folder to /d/vm on the virtual machine, then you can change the volumes section of your docker compose file to - /d/vm/zemke2/laradock:/var/www/laravel

Also see this answer docker toolbox: Is there a way to mount other folders than from c:\Users Windows?

Comments