Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boot2docker startup script to mount local shared folder with host

I'm running boot2docker 1.3 on Win7.

I want to connect a shared folder.

In the VirtualBox Manager under the image properties->shared folders I've added the folder I've want and named it "c/shared". The "auto-mount" and "make permanent" boxes are checked.

When boot2docker boots, it isn't mounted though. I have to do an additional:

sudo mount -t vboxsf c/shared /c/shared

for it to show up. Since I need that for every time I'll ever use docker, I'd like that to just run on boot, or just already be there. So I thought if there were some startup script I could add, but I can't seem to find where that would be.

Thanks

EDIT: It's yelling at me about this being a duplicate of Boot2Docker on Mac - Accessing Local Files which is a different question. I wanted to mount a folder that wasn't one of the defaults such as /User on OSX or /c/Users on windows. And I'm specifically asking for startup scripts.

like image 219
phazei Avatar asked Oct 29 '14 20:10

phazei


2 Answers

/var/lib/boot2docker/bootlocal.sh fits your need probably, it will be run by initial script /opt/bootscripts.sh

And bootscripts.sh will also put the output into the /var/log/bootlocal.log, see segment below (boot2docker 1.3.1 version)

# Allow local HD customisation
if [ -e /var/lib/boot2docker/bootlocal.sh ]; then
   /var/lib/boot2docker/bootlocal.sh > /var/log/bootlocal.log 2>&1 &
fi 

One use case for me is

I usually put shared directory as /c/Users/larry/shared, then I add script

#/bin/bash
ln -s  /c/Users/larry/shared /home/docker/shared

So each time, I can access ~/shared in boot2docker as the same as in host

see FAQ.md (provided by @KCD)

like image 133
Larry Cai Avatar answered Oct 19 '22 09:10

Larry Cai


If using boot2docker (Windows) you should do following:

First create shared folder for boot2docker VM:

"C:/Program Files/Oracle/VirtualBox/VBoxManage" sharedfolder add default -name some_shared_folder -hostpath /c/some/path/on/your/windows/box

#Then make this folder automount 
docker-machine ssh
vi /var/lib/boot2docker/profile

Add following at the end of profile file:

sudo mkdir /windows_share
sudo mount -t vboxsf some_shared_folder /windows_share

Restart docker-machine

docker-machine restart

Verify that folder content is visible in boot2docker:

docker-machine ssh
ls -al /windows_share

Now you can mount the folder either using docker run or docker-compose. Eg:

docker run it --rm --volume /windows_share:/windows_share ubuntu /bin/bash
ls -al /windows_share

If changes in the profile file are lost after VM or Windows restart please do following:

1) Edit file C:\Program Files\Docker Toolbox\start.sh and comment out following line:

#line number 44 (or somewhere around that)
yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"

#change the line above to:
#  yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"
like image 7
rgrebski Avatar answered Oct 19 '22 08:10

rgrebski