简体   繁体   English

boot2docker启动脚本,用于在主机上挂载本地共享文件夹

[英]boot2docker startup script to mount local shared folder with host

I'm running boot2docker 1.3 on Win7. 我在Win7上运行boot2docker 1.3。

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". 在图像属性 - >共享文件夹下的VirtualBox Manager中,我添加了我想要的文件夹,并将其命名为“c / shared”。 The "auto-mount" and "make permanent" boxes are checked. 检查“自动安装”和“永久”框。

When boot2docker boots, it isn't mounted though. 当boot2docker启动时,它不会挂载。 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. 因为我每次都需要使用docker,所以我希望它只是在启动时运行,或者只是已经在那里。 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. 编辑:我大吼大叫这是在Mac上重复Boot2Docker - 访问本地文件这是一个不同的问题。 I wanted to mount a folder that wasn't one of the defaults such as /User on OSX or /c/Users on windows. 我想安装一个不是默认文件夹的文件夹,例如OSX上的/ User或Windows上的/ c / Users。 And I'm specifically asking for startup scripts. 我特意要求启动脚本。

/var/lib/boot2docker/bootlocal.sh fits your need probably, it will be run by initial script /opt/bootscripts.sh /var/lib/boot2docker/bootlocal.sh可能符合您的需要,它将由初始脚本/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) bootscripts.sh也会将输出放入/var/log/bootlocal.log ,请参阅下面的段(boot2docker 1.3.1版本)

# 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 我通常把shared目录作为/c/Users/larry/shared ,然后我添加脚本

#/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 所以每次,我都可以像在主机中一样访问boot2docker中的~/shared

see FAQ.md (provided by @KCD) FAQ.md (由@KCD提供)

If using boot2docker (Windows) you should do following: 如果使用boot2docker(Windows),您应该执行以下操作:

First create shared folder for boot2docker VM: 首先为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

docker-machine restart

Verify that folder content is visible in boot2docker: 验证文件夹内容在boot2docker中是否可见:

docker-machine ssh
ls -al /windows_share

Now you can mount the folder either using docker run or docker-compose. 现在,您可以使用docker run或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: 如果在VM或Windows重新启动后丢失配置文件中的更改,请执行以下操作:

1) Edit file C:\\Program Files\\Docker Toolbox\\start.sh and comment out following line: 1)编辑文件C:\\ Program Files \\ Docker Toolbox \\ start.sh并注释掉以下行:

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

#change the line above to:
#  yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"

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: 我需要添加一些额外的标志,以便boot2docker“docker”用户可以访问新的mount:

sudo mount -t vboxsf -o umask=0022,gid=50,uid=1000 Ext-HD /Volumes/Ext-HD

I can't make it work following Larry Cai's instruction. 按照Larry Cai的指示,我不能让它发挥作用。 I figured I could make changes to "c:\\Program Files\\Boot2Docker for Windows\\start.sh", add below 我想我可以更改“c:\\ Program Files \\ Boot2Docker for Windows \\ start.sh”,在下面添加

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

your mount command 你的mount命令

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

With docker 1.3 you do not need to manually mount anymore. 使用docker 1.3,您无需再手动安装。 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/ https://blog.docker.com/2014/10/docker-1-3-signed-images-process-injection-security-options-mac-shared-directories/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM