问题描述
根据这个,当您启动一个容器时,它将自动共享您的 / Users / username
。
我当前的问题:
但在我的学校,我的 $ HOME
不在 / Users
,当我尝试直接在我的容器上装载这样的东西,如 docker run -d -P -v $ HOME / site:/ usr / share / nginx / html --name mysite nginx
(像链接中的教程),我无法通过挂载的卷更改文件。所以我想我的 $ HOME
不会自动共享。
但是,如果我运行 docker stpect mysite
我得到:
HostConfig:{
绑定 [
/ nfs / zfs-student-3 / users / vmonteco / site:/ usr / share / nginx / html
],
和
挂载:[
{
源:/ nfs / zfs-student-3 / users / vmonteco / site,
目的地:/ usr / share / nginx / html,
:,
RW:true,
传播:rprivate
}
我的问题只是这样:
我如何手动共享虚拟机托管坞站(virtualbox here)到目录使用它作为音量安装点?
这是我在不推荐使用Boot2docker之前做的:
使用 boot2docker ,我可以运行如下:
SHAREDIR = $ HOME / share
#创建共享文件夹。
mkdir $ SHAREDIR
#mount共享文件夹,同时重新启动boot2docker:
boot2docker --vbox-share =$ SHAREDIR = shareup
echo创建和安装boot2docker VM中的\share\目录。
boot2docker sshsudo mkdir / share; sudo mount -t vboxsf share / share
#运行容器:
docker run -ti --rm -v / share: / share -v / Users:/ Users base / archlinux sh
它工作正常。 >
但是现在, boot2docker 是已弃用,我没有找到如何使用虚拟机我现在必须使用它使用virtualbox)。
如果我理解的很好,它应该像boot2docker一样工作:
1 2
[来自OSX的目录]< ===> [VM目录(VM替换Boot2docker)]< ===> [容器目录]
如果我仍然很了解,现在唯一不起作用的是 [1] ,这是由我刚刚与boot2docker共享的小脚本的中间部分处理。
但是现在该怎么办? / p>
请看这个答案:
总结:
开始docker 1.8可以通过vbox cli添加目录。
VBoxManage共享文件夹添加<机器名/ id> --name< mount_name> --hostpath< host_dir> --automount
According to this tutorial from docker website, When you start a container it automatically shares your /Users/username
.
My current problem :
But in my school my $HOME
isn't in /Users
, and when I try to directly mount volumes on my container with something like docker run -d -P -v $HOME/site:/usr/share/nginx/html --name mysite nginx
(like the tutorial from the link), I can't change files through the mounted volume. So I guess my $HOME
isn't automatically shared.
But if I run docker instpect mysite
I get :
"HostConfig": {
"Binds": [
"/nfs/zfs-student-3/users/vmonteco/site:/usr/share/nginx/html"
],
and
"Mounts": [
{
"Source": "/nfs/zfs-student-3/users/vmonteco/site",
"Destination": "/usr/share/nginx/html",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
My question is simply this :
How could I manually share directories with the VM hosting docker (virtualbox here) to use it as volume mounting points?
This is how I did it with Boot2docker before it was deprecated :
With boot2docker I could have run something like :
SHAREDIR=$HOME/share
# creating share folder.
mkdir $SHAREDIR
# mount shared folder while relaunching boot2docker :
boot2docker --vbox-share="$SHAREDIR=share" up
echo "Creating and mounting \"share\" directory in boot2docker VM."
boot2docker ssh "sudo mkdir /share; sudo mount -t vboxsf share /share"
# running the container :
docker run -ti --rm -v /share:/share -v /Users:/Users base/archlinux sh
And it worked fine.
But now boot2docker is deprecated and I didn't find how to do this with the VM I have to use now (it uses virtualbox).
If I understand well, it should work the same way as boot2docker worked :
1 2
[directory from OSX] <===> [VM directory (the VM replaces Boot2docker)] <===> [container directory]
If I still understand well the only that doesn't work now is the point [1], this was handled by the middle part of the little script I just shared with boot2docker.
But how could I do now?
See this answer:https://stackoverflow.com/a/32030385/2434234
In summary:Starting in docker 1.8 you can add directories through the vbox cli.
VBoxManage sharedfolder add <machine name/id> --name <mount_name> --hostpath <host_dir> --automount
这篇关于在OSX上手动共享目录作为Docker卷安装点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!