Chris
Chris

Reputation: 3269

Boot2Docker on Mac - Accessing Local Files

I've just set up boot2docker on my Mac. How do I go about mounting a local directory on my Mac so that it's accessible all the way through to a running Docker container? Thanks for your help!

Upvotes: 12

Views: 8819

Answers (4)

Eli
Eli

Reputation: 39009

As Levi mentioned, the /Users directory is auto-mounted. This is true in both boot2docker and docker-machine. That said, if you want to mount anything outside of /Users, all the current answers talk about Boot2docker. Since that's now deprecated in favor of docker-machine, this works for docker-machine:

First, ssh into the docker-machine vm and create the folder we'll be mapping to:

docker-machine ssh $MACHINE_NAME "sudo mkdir -p \"$VOL_DIR\""

Now share the folder to VirtualBox:

WORKDIR=$(basename "$VOL_DIR")
vboxmanage sharedfolder add "$MACHINE_NAME" --name "$WORKDIR" --hostpath "$VOL_DIR" --transient

Finally, ssh into the docker-machine again and mount the folder we just shared:

docker-machine ssh $MACHINE_NAME "sudo mount -t vboxsf -o uid=\"$U\",gid=\"$G\" \"$WORKDIR\" \"$VOL_DIR\""

Note: for UID and GID you can basically use whatever integers as long as they're not already taken.

This is tested as of docker-machine 0.4.1 and docker 1.8.3 on OS X El Capitan.

Upvotes: 0

dnozay
dnozay

Reputation: 24344

boot2docker with share other than /Users

see https://github.com/boot2docker/boot2docker/issues/678.

Share your folder with the VM:

VBoxManage sharedfolder add boot2docker-vm --name /tmp/Work --hostpath /CODE --automount

Based on info found un bootscript.sh, you know that the VM will run a bootlocal.sh script that is in the /var/lib/boot2docker folder, where data persists.

Add a file /var/lib/boot2docker/bootlocal.sh

#!/bin/sh
# bash is not available!
mkdir -p /CODE
mount -t vboxsf /tmp/Work /CODE

Then chmod +x /var/lib/boot2docker/bootlocal.sh and reboot your boot2docker-vm vm.

Upvotes: 7

user798377
user798377

Reputation:

As of October 16, 2014, Docker supports mounting directories in the /Users path seamlessly.

From the Docker blog:

With this release we are addressing the most common issue: sharing directories between your Mac and your containers. Using Docker 1.3 with the corresponding version of boot2docker, host-mounted volumes now work the way you expect them to.

...Note that there are still some limitations: for example this feature is limited to boot2docker’s virtualbox configuration, cannot be managed dynamically, and only works for directories in /Users . But we are receiving exciting contributions to improve volume management, so expect this area to improve drastically in the next few releases.

Example usage: $ docker run -v /Users/bob/myapp/src:/src [...]

Upvotes: 11

mattes
mattes

Reputation: 9429

boot2docker together with VirtualBox Guest Additions
How to mount /Users into boot2docker

https://medium.com/boot2docker-lightweight-linux-for-docker/boot2docker-together-with-virtualbox-guest-additions-da1e3ab2465c

tl;dr Build your own custom boot2docker.iso with VirtualBox Guest Additions (see link) or download http://static.dockerfiles.io/boot2docker-v1.0.1-virtualbox-guest-additions-v4.3.12.iso and save it to ~/.boot2docker/boot2docker.iso.

Upvotes: 3

Related Questions