boot2docker startup script to mount local shared folder with host
Asked Answered
B

5

24

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.

Bellanca answered 29/10, 2014 at 20:23 Comment(1)
possible duplicate of Boot2Docker on Mac - Accessing Local FilesCounseloratlaw
C
20

/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)

Cawley answered 16/11, 2014 at 15:16 Comment(5)
using docker version 1.6.2, everytime I edit /opt/bootlocal.sh to add start up command it vanishes when restarted.Thorma
it shall be /var/lib/boot2docker/boot2docker.sh, I don't know why @user3699741 edited my answer to wrong indication.Cawley
Nailed it!!! One QQ: where does the symlink /var/lib/boot2docker get mapped to on my host machine?Mayworm
@EricManley , not sure which host machine do you mean ? if windows, no, it exist in docker host machines only.Cawley
Documented here: github.com/boot2docker/boot2docker/blob/17.03.x/doc/…Doodle
P
7

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}"
Preengage answered 7/6, 2016 at 23:55 Comment(0)
S
3

Thanks for your help with this. An additional few flags I needed to add, in order for the new mount to be accessible by the boot2docker "docker" user:

sudo mount -t vboxsf -o umask=0022,gid=50,uid=1000 Ext-HD /Volumes/Ext-HD
Scrag answered 25/7, 2015 at 3:43 Comment(0)
D
1

With docker 1.3 you do not need to manually mount anymore. Volumes should work properly as long as the source on the host vm is in your user directory.

https://blog.docker.com/2014/10/docker-1-3-signed-images-process-injection-security-options-mac-shared-directories/

Dallasdalli answered 29/10, 2014 at 20:37 Comment(1)
Yes, the user directory is auto mounted at /c/Users. I wanted an additional directory at /c/shared. And I can get it, but I always have to mount it even though it's added in the shared folders in the vm, right next to the Users one.Bellanca
T
1

I can't make it work following Larry Cai's instruction. I figured I could make changes to "c:\Program Files\Boot2Docker for Windows\start.sh", add below

eval "$(./boot2docker.exe shellinit 2>/dev/null | sed 's,\\,\\\\,g')"

your mount command

eval "$(./boot2docker ssh 'sudo mount -t vboxsf c/shared /c/shared')"

I also add the command to start my container here.

eval "$(docker start KDP)"

Thorma answered 6/7, 2015 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.