Docker无法在Windows上挂载文件夹 [英] Docker can't mount folder on Windows

查看:157
本文介绍了Docker无法在Windows上挂载文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Windows上的Docker上安装文件夹.我正在使用存储库 https://github.com/LaraDock/laradock .在docker-compose.yml的第23行中,有一个文件夹映射:

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

在VirtualBox文件夹中,共享D:\VM.当我启动容器并列出文件时,只有laradock文件夹,但是我有一个完整的 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#

当我尝试从Docker进行绑定时,它处于静默状态,但未挂载该文件夹,并且未列出文件.

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"
            ]
        }
    }
]

推荐答案

在使用Docker Toolbox时,将文件夹安装到容器的过程分为两个步骤.在Windows/OS X上,Docker在 VirtualBox VM内运行.首先,您需要将Windows/OS X文件夹安装到VirtualBox.其次,然后可以使用卷将VirtualBox文件夹安装到Docker. Docker除了用户文件夹外,无权访问您的Windows/OS X文件夹(这是因为VirtualBox虚拟机默认将该文件夹安装到该虚拟机)

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)

如果将D:/VM文件夹安装到虚拟机上的/d/vm,则可以将Docker Compose文件的"volumes"部分更改为- /d/vm/zemke2/laradock:/var/www/laravel

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?

这篇关于Docker无法在Windows上挂载文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆