2

I can't mount a folder on Docker on Windows. I'm using the repository https://github.com/LaraDock/laradock. In docker-compose.yml, line 23, there is a folders mapping:

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

In the VirtualBox folder, D:\VM is shared. When I start the container and list files there is just the laradock folder, but I have a 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 the 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 the folder isn't mounted, and 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 information for a container that defines volume mapping:

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"
            ]
        }
    }
]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
S S
  • 987
  • 1
  • 9
  • 20
  • 1
    Docker Toolbox can only mount folders inside your `User` folder by default. http://stackoverflow.com/questions/33245036/docker-toolbox-is-there-a-way-to-mount-other-folders-than-from-c-users-windows – Xiongbing Jin May 23 '16 at 20:45
  • I did try that first (to mount on desktop), it is completely same situation. – S S May 23 '16 at 20:49
  • See my attempts to mount manually, also I did change default mounted dir from User to D:\VM in virtualbox. – S S May 23 '16 at 21:02
  • 1
    That `mount -t vboxsf` command should be run inside the virtualbox vm, not inside a docker container. – Xiongbing Jin May 23 '16 at 21:12
  • VM doesn't have /var/www/laravel folder i want to bind to, container does. – S S May 23 '16 at 21:26
  • 1
    This is a two step process. On Windows, Docker runs inside a Virtualbox VM. First, you need to mount your Windows folder to Virtualbox; second, you can then mount the virtualbox folder to Docker using volumes. Docker does not have access to your Windows folders except the `User` folder (which is because the Virtualbox VM mounts that Windows folder to the VM by default) – Xiongbing Jin May 23 '16 at 21:32
  • It's a progress, mount -t vboxsf -o uid=1000,gid=50 VM /var does mount D:\VM folder. So what folders should I bind in machine to map D:\VM\zemke2 to /var/www/laravel and what laradock container expect? Only /var exists in machine. – S S May 23 '16 at 21:33
  • 1
    If you mount the folder to /var, then use /var as a volume. Although I would suggest another mount point, as /var normally container other essential linux files. – Xiongbing Jin May 23 '16 at 21:35
  • Yes that relation what is mounted on machine level, and what on container level is not clear to me. Is it enough that volumes are below folder that is mounted on machine level? I want to mount to /var/www/laravel that doesn't exist in machine, only in container. – S S May 23 '16 at 21:36
  • 1
    I don't understand this question. But say 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` (or one of the subfolders. You will know the correct path better than me). – Xiongbing Jin May 23 '16 at 21:43
  • Should i create /var/www/laravel in machine and container will reuse folder? Edit: So in volumes mapping both path are from within container? I'll try what you wrote. – S S May 23 '16 at 21:43
  • It is working http://s33.postimg.org/kwsx1zlvj/Capture.png .Can you write 3rd and last comment as answer so I can mark it? – S S May 23 '16 at 22:05

2 Answers2

4

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Xiongbing Jin
  • 11,779
  • 3
  • 47
  • 41
  • One more thing. VM loses mount and /d/vm folders on every machine restart. Don't know how to make it permanent? – S S May 24 '16 at 21:17
  • 1
    See if this helps http://askubuntu.com/questions/52328/mount-virtualbox-sharedfolder-in-ubuntu-vm-on-boot – Xiongbing Jin May 25 '16 at 14:00
1

For those who are using Docker for Windows (on Hyper-V):

If you experience this issue when using Laradock or any other container, please make sure you select your drives under Shared Drives and add the credentials of a user with access to those same drives. Some people also have experienced this same issue when their passwords contain spaces or special characters. It's also worth noting that you should add your username like this: hostip\username

Another possible solution would be to temporarily disable your firewall and restarting Docker. I've seen this as being a more popular cause of Docker not being able to view project folders/filers. You'd need allow communication to/from the docker IP address, or better yet, change the policy of the virtual network adapter to one where sharing files/printers is allowed (i.e Private Network - this mainly depends of your own settings).

For even more solutions you might want to visit the Docker forums. This thread in particular contains heaps of other possible solutions, as this is a very common issue in the Windows environment.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ivanji
  • 169
  • 1
  • 10