7

I have an application that I eventually want to run on a cloud computing service (e.g., such as AWS or Google Cloud) packaged inside a docker image. The reason the application will need to run in the cloud is because it's designed to process large data files, but before I actually deploy, I'd like to test it first on a local laptop, using a single large data file that I've stored (for test and development purposes) on an external USB drive.

My development machine is an OSX laptop, and I'm using a recent version of docker:

stachyra> uname -a
Darwin Andrews-MacBook-Pro-76.local 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
stachyra> docker --version
Docker version 1.10.2, build c3959b1

OSX has mounted my external USB drive, device /dev/disk2s2, as /Volumes/MGR DATA:

stachyra> df
Filesystem    512-blocks       Used Available Capacity   iused    ifree %iused  Mounted on
/dev/disk1     974770480  435721376 538537104    45%  54529170 67317138   45%   /
devfs                375        375         0   100%       650        0  100%   /dev
map -hosts             0          0         0   100%         0        0  100%   /net
map auto_home          0          0         0   100%         0        0  100%   /home
/dev/disk2s2  3906291632 3869523640  36767992   100% 483690453  4595999   99%   /Volumes/MGR DATA
/dev/disk3s1      196608     193160      3448    99%     24143      431   98%   /Volumes/VirtualBox
stachyra> diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage                         499.4 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           *499.1 GB   disk1
                                 Logical Volume on disk0s2
                                 DB70B91A-3B57-4C82-A758-C4BDEA4160FD
                                 Unlocked Encrypted
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS MGR DATA                2.0 TB     disk2s2
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *100.7 MB   disk3
   1:                  Apple_HFS VirtualBox              100.7 MB   disk3s1

and it should also be noted, the drive has several directories and data which are visible inside it, at least when viewed directly through OSX:

stachyra> ls -l /Volumes/MGR\ DATA
total 0
drwxr-xr-x   6 stachyra  staff  204 Apr 14  2015 1000genomes
drwxr-xr-x   5 stachyra  staff  170 Oct 12 17:41 GIAB
drwxr-xr-x   4 stachyra  staff  136 Apr 28  2015 genome_browser_tracks
drwxr-xr-x  24 stachyra  staff  816 Oct  6 14:00 mitty

I have tried to follow the advice from this question, which describes how to mount a USB drive in docker when docker is running within a linux host. But my local laptop is OSX, not linux, so it doesn't seem to work.

Explicitly, when attempting to follow the advice of the accepted answer, I obtain the following result:

stachyra> docker run -i -t --privileged -v /dev/disk2s2:/dev/foo ubuntu bash
root@8da7b492a707:/# uname -a
Linux 8da7b492a707 4.1.18-boot2docker #1 SMP Sat Feb 20 08:24:27 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
root@8da7b492a707:/# ls -l /dev/foo
total 0
root@8da7b492a707:/# 

Based upon the response, one can see that docker does indeed launch a linux container correctly, and it also creates a volume /dev/foo inside of the container as requested, but the actual contents of the USB drive are not accessible via that location--the ls -l command claims there are no files or directories there.

I also tried the second method described in an alternate response to the same question, and that fails even worse:

stachyra> docker run -i -t --device=/dev/disk2s2 ubuntu bash
docker: Error response from daemon: error gathering device information while adding custom device "/dev/disk2s2": not a device node.
                                                                                                                                stachyra> 

I have found another discussion thread on stackoverflow which suggests that raw USB access is handled quite differently in OSX than in linux, which I suspect is probably the reason why both of the above attempts at USB access are failing.

But, what should I actually do about it? That is to say, what is the correct sequence of actions or commands to allow docker to access a USB device mounted on an OSX host, rather than linux?

Community
  • 1
  • 1
stachyra
  • 4,423
  • 4
  • 20
  • 34
  • Try this http://stackoverflow.com/questions/30040708/how-to-mount-local-volumes-in-docker-machine/32030385#32030385 – Xiongbing Jin Mar 08 '16 at 00:19
  • @warmoverflow: thanks, that was somewhat helpful, but unfortunately it doesn't quite get me all the way there. I was indeed able to follow the steps outlined in that other answer to mount a USB drive inside of an Oracle VM Virtualbox *virtual* *machine* (specifically, within the "default" machine that docker seems to be using to run docker engine), however, it doesn't seem to work the same inside of a docker *container*--the mount command gives me a permission denied error. How do I mount a USB drive inside of a docker container, specifically? – stachyra Mar 08 '16 at 20:33
  • Did you follow the `boot2docker` section and used `uid` exactly as in the answer? That might be the key to the permission problem. – Xiongbing Jin Mar 08 '16 at 20:48
  • Inside of the terminal console for "default" virtual machine, which I access via the "Show" button in the Oracle VM VirtualBox Manager GUI, I follow the instructions exactly (except that I omit sudo because I am already root). This results in a correct mount, with the user ID set to "docker", and the group ID set to "staff", all the way down the directory tree. Inside of a docker container OTOH (where I'm also root), following instructions exactly generates an error "id: docker: no such user". If I omit the part that tries to set user and group IDs, then I only get the permissions error. – stachyra Mar 08 '16 at 22:04
  • You don't need to do it inside the container. Once you have the correct mount to the `default` machine, just run `docker run -v mount_path:container_path your_image` and then you can access the content of your USB from `container_path`. – Xiongbing Jin Mar 08 '16 at 23:55
  • BTW here is a script specifically for mac, provided in the link above. https://gist.github.com/cristobal/fcb0987871d7e1f7449e The README also mentioned an alternative, which is to mount the USB to a subfolder of your `/Users` folder, thus make it available to `default` docker machine without any sharedfolder. – Xiongbing Jin Mar 09 '16 at 00:34
  • Related: [How to mount a device of host to host in a Docker container?](https://stackoverflow.com/q/38736319/55075) – kenorb Jul 22 '18 at 00:17

2 Answers2

3

I was finally able to access my USB drive from /var/media inside my container by using the machine-diskutil.sh script mentioned in warmoverflow's comment like so

machine-diskutil.sh mount my-machine-name /Volumes/my-usb-drive

and then starting the container like so

docker run -v /Volumes/my-usb-drive:/var/media -it my/image:latest bash

Because I had tried to add /Volumes/my-usb-drive as a shared folder manually in VirtualBox, I first got this error.

Error: The shared folder /Volumes/Seagate already exists on the docker machine, please unmount it first.

So I removed it manually and re-ran the machine-diskutil.sh mount command without any problems. Great stuff!

Nick Weisser
  • 910
  • 1
  • 9
  • 21
  • Sadly, this will only work if you can mount the device - in my case, it's an ext4 filesystem, and I cannot mount it. Based on searches, I'm guessing this simply isn't possible without creating a custom installation of docker-in-a-vm using docker-machine. – tsalaroth Nov 25 '18 at 15:10
0

As per @pgayvallet comment on GitHub:

As the daemon runs inside a VM in Docker Desktop, it is not possible to actually share a mac host device with the container inside the VM, and this will most definitely never be possible.

kenorb
  • 155,785
  • 88
  • 678
  • 743