moby / moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems
https://mobyproject.org/
Apache License 2.0
68.66k stars 18.65k forks source link

Empty folder in container when mounting a host directory #22981

Closed aharpervc closed 8 years ago

aharpervc commented 8 years ago

Output of docker version:

Client:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Wed Apr 27 00:34:20 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Wed Apr 27 00:34:20 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1
Server Version: 1.11.1
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 7
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 4.4.8-boot2docker
Operating System: Boot2Docker 1.11.1 (TCL 7.0); HEAD : 7954f54 - Wed Apr 27 16:36:45 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 995 MiB
Name: test-machine
ID: KAM5:NASP:4VCU:TM2C:GFQR:QOZ3:S3CT:N4CM:FRNJ:HHGU:UNFO:2D4L
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug mode (client): false
Debug mode (server): true
 File Descriptors: 12
 Goroutines: 30
 System Time: 2016-05-25T15:29:28.874791658Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
 provider=hyperv

Additional environment details (AWS, VirtualBox, physical, etc.):

Steps to reproduce the issue:

Here's my full command history

  1. create new folder, and create a new text file in the folder
  2. run docker-machine create test-machine
  3. run the commands to set up the environment
  4. run docker run -i -t -v /c/users/aharper/workspace_test_docker_volume:/whatever ubuntu /bin/bash

Describe the results you received:

I expected to see the host folder contents in /whatever in the container

Describe the results you expected:

/whatever exists in the container but is empty

Additional information you deem important (e.g. issue happens only occasionally):

Seems to always happen. No errors that I noticed. The mounting process seems to almost work since the folder itself shows up.

thaJeztah commented 8 years ago

I've seen some reports where the Windows/VirtualBox shared mount wasn't started properly in the virtual machine. Could you try restarting the VirtualBox VM?

Also, if you didn't do so yet, I recommend registering for the Docker for Windows beta, which solves a lot of these issues (https://github.com/docker/docker/issues/21535#issuecomment-201687341). You can register at https://beta.docker.com; feel free to ping me here after you did so, and if you give me your Docker Hub ID (username), I can try getting you into the beta faster

aharpervc commented 8 years ago

I created the docker machine with Hyper-V, not VirtualBox, however restarting the vm did not seem to change the situation. Docker Hub username is aharper.

friism commented 8 years ago

@aharpervc @thaJeztah I don't think the hyper-v driver does host (win) to guest (boot2docker) filesharing, so volume-mounting from the host windows 10 filesystem is not expected to work.

@thaJeztah seperately, it might be good to document what machine drivers are expected to have working host volume mounting (only the virtualbox one, as far as I know)

thaJeztah commented 8 years ago

Ah! Yes, the Hyper-V machines don't have this as an option, only VirtualBox (and Docker for Windows)

@friism probably, yes, but that should go in the https://github.com/docker/machine issue tracker. Could you open an issue there?

@aharpervc looks like that answers your question, so I'll close this issue, but feel free to continue the discussion here :+1:

friism commented 8 years ago

@thaJeztah done: https://github.com/docker/machine/issues/3455

aharpervc commented 8 years ago

Hopefully that doc change will make its way into the website, which is silent on this critical deficiency and implies that it will work normally.

https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume

On Windows, mount directories using:

docker run -v /c/Users/:/ ...`

thaJeztah commented 8 years ago

@aharpervc I agree we should have something mentioning it. It's sometimes difficult finding the right balance, because this basically is an issue in docker machine, not "docker (engine)", and there's now four possible setups on Windows (native Windows docker, Docker toolbox (VirtualBox), Docker Machine (Hyper-V), and "Docker for Windows (beta)"

carrete commented 8 years ago

This happens for us when using Docker for Windows (beta)

thaJeztah commented 8 years ago

@carrete I'm not on Windows myself, but could you check this section? https://beta.docker.com/docs/windows/troubleshoot/#host-filesystem-sharing

rebeccamadsen commented 8 years ago

I enabled file and printer sharing on Windows 10, following that section. When I try to enable sharing a local drive using Docker Beta, the username/password screen just keeps popping up again whenever I click submit.

carrete commented 8 years ago

Thanks @thaJeztah . We tried that, but the problem is as @rebeccamadsen describes: https://github.com/docker/docker/issues/22981#issuecomment-221746631. She opened an issue about this: https://github.com/docker/docker/issues/23005

aharpervc commented 8 years ago

I have the "Docker for Windows" beta, and confirmed that it's still an issue. Additionally, under the "Shared Drives" panel of the Settings screen, the command docker run -v c:/Users:/data alpine ls /data is suggested, but doesn't work (returns empty listing.... no files in mounted folder)

thaJeztah commented 8 years ago

Apparently there are still some issues with sharing host-mounts on Windows with the Docker for Windows beta. The best source of information currently is the troubleshooting documentation linked above, and this forum topic on the docker for windows beta forum; https://forums.docker.com/t/volume-mounts-in-windows-does-not-work/10693/53

thaJeztah commented 8 years ago

I realize that's not a full answer, but I know the Docker for Windows team is working hard to improve the reliability of this feature on Windows. :blush:

habbes commented 8 years ago

@thaJeztah I have the same problem on my machine. The directory is created in the container but is empty, it is also properly listed in Mounts when I run docker inspect. However it worked fine last week when I tried it out a couple of times, don't know why it's not working today. I have the Docker Toolbox and VirtualBox setup.

thaJeztah commented 8 years ago

@habbes you could try a reboot of the VM; I heard that helped some people, where VirtualBox file-sharing wasn't started for some reason

habbes commented 8 years ago

@thaJeztah I tried that, tried restarting the docker machine, virtualbox and even the whole computer. Nothing. Let me keep searching for a solution

habbes commented 8 years ago

@thaJeztah It's working now. Not really sure where I went wrong. I notice it works if I map the volume to a directory that doesn't exist in the docker container. If I map it to an existing directory, it comes empty. I don't know whether that's the expected behavior. Thanks anyway.

KevinM2k commented 8 years ago

I have same issue on windows for beta, it creates the folder in the container but doesn't have the contents of the drive from the windows dir

thaJeztah commented 8 years ago

@KevinM2k can you report that issue in the Docker for Windows beta forum? I think there's already a topic for it https://forums.docker.com/c/docker-for-windows

jimudall commented 8 years ago

Beyond strange. I've been working on this all day. I'm using Windows 7 and Docker Toolbox. Here's how it started

  1. Mounting of a Virtualbox shared container was working
  2. I then wanted to mount a different folder in my container (albeit still in the shared folder of my host machine)
  3. When I did so, the mount in the container SORT of worked. In particular, it merged the old folder with the new one! Tres bizzare!
  4. Been jumping through ALL the hoops google has been suggesting...including destroying the VM. Nothing works...EXCEPT 5 Now it doesn't matter what folder I try to mount. If it's a shared folder from the host, it shows up as empty in the container
  5. Mounting a non-shared folder seems fine.
  6. Totally stumped. I can't even get back to the merged behaviour
MoOx commented 8 years ago

This might help https://docs.docker.com/docker-for-windows/troubleshoot/#/host-filesystem-sharing

Unfortunately, this setup does not support passwords which contain Unicode characters, so your password must be 8-bit ASCII only.

aharpervc commented 8 years ago

The guidance in this comment, to change the DockerNAT virtual adapter from public to private network type, fixed the issue for me.

aharpervc commented 8 years ago

I spoke too soon... it worked exactly once, but subsequent docker run commands still show a blank mounted folder.

patrick-mota commented 8 years ago

Instead of docker run -v c:/Users:/data alpine ls /data

You can use /c/Users:/data alpine ls /data

Details: PS C:\Windows\system32> docker run -v /c/Users:/data alpine ls /data Unable to find image 'alpine:latest' locally latest: Pulling from library/alpine e110a4a17941: Pull complete Digest: sha256:3dcdb92d7432d56604d4545cbd324b14e647b313626d99b889d0626de158f73a Status: Downloaded newer image for alpine:latest Patrick

It works the same way in my PHPStorm, instead of browsing a local directory I just do /c/Users.........

Hope it helps.

oliversalzburg commented 8 years ago

I found this process to be very confusing as well.

The documentation seems to suggest that you can either share a complete host volume or a host directory at a specific mount point in the guest.

However, with Hyper-V on Windows 10, I was not able to mount a host directory and see its contents inside the guest. I always ended up with an empty directory.

I had to check my C drive in the Docker settings as a shared drive and then the directory contents would be visible inside the guest.

image

friism commented 8 years ago

@oliversalzburg sorry about the confusion. The docs you want are for Docker for Windows: https://docs.docker.com/docker-for-windows/#/shared-drives

oliversalzburg commented 8 years ago

@friism What was confusing me was that I need to share what seems like "the whole drive" so that I can see the contents of a single mounted directory in my container. I don't see how the link you gave me relates to that.

The silent failure here is really unfortunate. When I'm attempting to -v c:/foo:/foo, I would expect some kind of feedback if I haven't enabled the appropriate setting.

Another, more minor, fix would probably be making the line below Shared Drives fully readable and have it explain what it really means to check one of those boxes.

Select the local drives you want to be able to … your containers.

The part that is cut off there seems very relevant to me to understand the meaning behind these settings.

Anyway, I was primarily just leaving this here, in case anyone was running into the same situation I was :)

friism commented 8 years ago

@oliversalzburg

share what seems like "the whole drive" so that I can see the contents of a single mounted directory in my container

Yeah, it's not the best. The alternative is worse, though, because Docker would have to share host folders on each container run, and that would potentially pop up the credentials prompt.

The silent failure here is really unfortunate

We agree, and we're working on improving this with a warning or similar

Another, more minor, fix would probably be making the line below Shared Drives fully readable

The text you quoted is not what I'm seeing (and it's not what's in the screenshot above). If you're seeing something else, could you post a screenshot here?

Thanks again for your comments and suggestions!

oliversalzburg commented 8 years ago

@friism Huh, I must have read that line like a dozen times and did not parse it correctly. Sorry for the mistake :)

carrete commented 8 years ago

@friism Huh, I must have read that line like a dozen times and did not parse it correctly. Sorry for the mistake :)

Same.

wmario commented 8 years ago

Hi guys

I think I've just revolved the same issue on my W10 :

I moved my windows to latest release (1607) Then I went on Hyper-v to check the VM Management Integration services : I uncheck all an check back all option there (included guest services and data sharing)... Restarted using Docker applet then it workked....

As i upgraded W10 from 1511 to 1607, I do not know if it is my Hyper-v options checking tour which changed any thing... Or the upgrade.

I'll try now to install docker on a Windows Server 2012R2 and will let you know.

marc1404 commented 8 years ago

@wmario I tried your steps but without upgrading Windows 10. Shared folders are still empty for me inside the guest container. Windows 10 Pro Version 1511 Docker for Windows Version 1.12.0-stable (build: 5968)

wmario commented 8 years ago

Hi Sorry for this I am running latest build of docker 1.21.1-beta25 build 6823... And it is still running.

Si maybe it is the latest w10 hyper-v which revolves the issue... 🙁

wmario commented 8 years ago

I upgraded docker to latest version (again)...

and again my shared drives was broken !!!

So I went to hyper-v console again to check this [image: Images intégrées 1] the last check boxe here was not checked ! again....

So I checked all and restart docker from the docker applet... And it is working again.

Best regards, Willy.

2016-09-14 17:48 GMT+02:00 Willy mario wmario.wm@gmail.com:

Hi Sorry for this I am running latest build of docker 1.21.1-beta25 build 6823... And it is still running.

Si maybe it is the latest w10 hyper-v which revolves the issue... 🙁

masaeedu commented 8 years ago

@friism Is there a particular reason this is done by asking you for your password instead of using UAC? Relying on Windows' built in elevation mechanism seems like it would be more secure and would bypass the unicode issues we're seeing. If the user doesn't like UAC prompts (e.g. if they're on a dev box) they'll already have the notification level set to low, or will run docker in an elevated process.

SeriousM commented 8 years ago

@thaJeztah could you please add me to the beta-list? name is SeriousM . I'm running Win10 and my shared folders are empty. Thank you!

friism commented 8 years ago

@SeriousM there's no beta list, you can install the beta-channel version from here: https://docs.docker.com/docker-for-windows/

SeriousM commented 8 years ago

Thank you, and sorry for the distribution!

Am 19.09.2016 21:57 schrieb "Michael Friis" notifications@github.com:

@SeriousM https://github.com/SeriousM there's no beta list, you can install the beta-channel version from here: https://docs.docker.com/ docker-for-windows/

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/docker/docker/issues/22981#issuecomment-248104922, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcMvYcu0hbCoAIIrHIARdy6npZPyWTjks5qrukqgaJpZM4ImqtR .

yuval-mntr commented 8 years ago

https://forums.docker.com/t/volume-mounts-in-windows-does-not-work/10693/71

soheilalizadeh commented 7 years ago

I installed Docker with Docker toolbox and this is how I solved it:

  1. Open the Oracle VM
  2. Go to the settings of the VM for docker (mine was default)
  3. Shared Folders
  4. Add new shared folder (e.g. I wanted to mount E:\X -> Folder path : E\X and Folder name: e/X)
  5. Shutdown the VM
  6. Run Docker terminal
deep-c commented 7 years ago

Hi I am experiencing the same problem and have exhausted everything i can think of. I am attempting to mount a volume from C:/Users into a container running on a docker-machine using the hyperv driver on docker for windows (win 10 pro). I am a using the lastest docker (1.13.1) and the same on the hyper vm machine. I have tried switching to using a local account, shared the drive in the docker settings menu and ive pretty much tried everything i could find on google.

Running the test volume run command in the settings menu works for me. At this point in time I presume hyperv does not support mounting volumes from the host however i cant find anywhere that explicitly says that volumes mounting will not work in hyperv.

This is my docker-compose config:

networks: {}
services:
  app:
    build:
      context: C:\users\deep\projects\chat\app
    command: sleep 3600
    image: app
    links:
    - rethinkdb
    - redis
    ports:
    - 4005:4005
    - 4007:4007
    volumes:
    - /c/users/deep/projects/chat/app:/usr/src/app:rw
  redis:
    image: redis
  rethinkdb:
    image: rethinkdb:2.3.5
version: '2.0'
volumes: {}

In my Dockerfile i can see copy files into the container to usr/src/app. When i up the services with the volume specified in the compose file the directory is emptied, however i omit this volume mount i can see my files that i copied into the container from the dockerfile.

Running verbose when starting my services i can see a volumes path specified as such 'Binds': [u'/c/users/deep/projects/chat/app:/usr/src/app:rw']. However, when i inspect the container using docker-compose inspect app i see volumes set to null "Volumes": null.

I presume at this point that mounting volumes into a container running inside a hyperv VM is not supported? Can someone confirm so that I can RIP :)

thaJeztah commented 7 years ago

@deep-c Docker for Windows supports bind-mounting host directories (see https://docs.docker.com/docker-for-windows/#shared-drives), however, if you use docker-machine to create a machine with hyperv, sharing won't work. I'd recommend to install Docker for Windows instead.

deep-c commented 7 years ago

@thaJeztah Thanks for the confirmation! I presume you mean i should install Docker toolbox (and use virtualbox) when you said I'd recommend to install Docker for Windows instead?

thaJeztah commented 7 years ago

@deep-c No, docker toolbox / VirtualBox should not be needed. If you use Docker for Windows https://docs.docker.com/docker-for-windows/install/, you should be able to use shared drives. Docker for Windows also uses hyper-v, but has additional features in place to allow you to do that. Those features are not there if you create a hyper-v machine with docker-machine.

alexgorbatchev commented 7 years ago

if you are trying to mount a folder from windows bash and getting empty results, you have to remove /mnt prefix...

so, instead of --volume /mnt/c/Users:/foo it should be --volume /c/User:/foo... Double slash also works --volume //c/User:/foo

omarramadan commented 6 years ago

Had the same issue This is on windows 10.. Solved it by doing the following Docker Setting -> Shared Drive -> Reset credentials. This was after I had changed my windows password.

snewell92 commented 6 years ago

@omarramadan I didn't even know I needed to grant those permissions by supplying credentials to the windows partitions 😮 . The tuts didn't really mention that...

thaJeztah commented 6 years ago

@snewell92 could you open an issue for that in the documentation issue tracker? There's a "request documentation changes" link on the page you referred to to open an issue

krufab commented 6 years ago

It's an old post, but this might help: On Windows, antivirus and similar softwares might prevent docker to access the local file system. Even if drive sharing is enabled on docker.