boot2docker startup script to mount local shared f

2019-01-11 01:06发布

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.

5条回答
forever°为你锁心
2楼-- · 2019-01-11 01:47

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/

查看更多
走好不送
3楼-- · 2019-01-11 01:51

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

查看更多
Fickle 薄情
4楼-- · 2019-01-11 02:10

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
查看更多
够拽才男人
5楼-- · 2019-01-11 02:10

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

查看更多
Deceive 欺骗
6楼-- · 2019-01-11 02:11

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}"
查看更多
登录 后发表回答