在OSX上挂载到Docker映像的卷 [英] Mount volume to Docker image on OSX

查看:121
本文介绍了在OSX上挂载到Docker映像的卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac上,如何将一个卷挂载到Docker容器?



在我的linux框中,这很简单。所有我需要做的就是运行容器时的 -v / src / webapp:/ opt / webapp 。但Mac是不同的,因为我必须运行boot2docker在VirtualBox中运行一个虚拟机。我试过运行

  boot2docker init 
boot2docker up
boot2docker ssh#to poke around
boot2docker stop
VBoxManage sharedfolder添加boot2docker-vm--nameUsers--hostpath / Users
boot2docker up
boot2docker sshsudo modprobe vboxsf

但我得到

  modprobe :module vboxsf在modules.dep中找不到

如果我忽略了,仍然尝试挂载在VM上像这样

  boot2docker sshsudo mkdir / test&&sudo mount -t vboxsf Users / test

我得到

  mount:mount用户在/ test失败:没有这样的设备

我觉得我错过了一些东西非常简单,但我不太清楚。任何帮助将不胜感激。

解决方案

好的,通过一个GitHub PR ,我能够找出一个方法来做到这一点。对于未来的读者来说,这个过程应该在即将发布的boot2docker中得到解决。

 #假设boot2docker和VirtualBox已安装
wget http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso
mv boot2docker-v1.2.0-virtualbox-guest-added-v4 .3.14.iso〜/ .boot2docker / boot2docker.iso
#吹掉你的旧boot2docker-vm(如果存在)(boot2docker down&& boot2docker destroy)
boot2docker init
boot2docker up
#根据指示设置DOCKER_HOST
boot2docker stop
VBoxManage sharedfolder添加boot2docker-vm --name / Users --hostpath / Users
boot2docker up
#如果你进入VM现在,你会注意到/用户存在,但是是空的;我不知道/关心为什么。
boot2docker sshsudo mount -t vboxsf -o uid = 1000,gid = 50 / Users / Users
#done

这对我有用,所以我希望它适用于其他人。在不久的将来,我希望这个问题可以通过boot2docker来解决,特别是因为我收到这些命令的PR被合并。



编辑:boot2docker 1.3.0支持此操作,无需进一步更改。更新后,我运行这些命令:

  boot2docker destroy#start over 
boot2docker download#下载udpated ISO
boot2docker init
boot2docker up
#done


On a Mac, how do you mount a volume to a Docker container?

On my linux box, this is easy. All I need to do is something like -v /src/webapp:/opt/webapp when running the container. But Mac is different since I have to run boot2docker to run a VM in VirtualBox. I've tried running

boot2docker init
boot2docker up
boot2docker ssh # to poke around
boot2docker stop
VBoxManage sharedfolder add "boot2docker-vm" --name "Users" --hostpath /Users
boot2docker up
boot2docker ssh "sudo modprobe vboxsf"

but I get

modprobe: module vboxsf not found in modules.dep

If I ignore that and still try to mount on the VM like so

boot2docker ssh "sudo mkdir /test && sudo mount -t vboxsf Users /test"

I get

mount: mounting Users on /test failed: No such device

I feel like I'm missing something extremely simple, but I can't quite figure it out. Any help would be greatly appreciated.

解决方案

Ok, after digging through a GitHub PR, I was able to figure out a way to do this. For the future readers out there, this process should be fixed in an upcoming release of boot2docker.

# assuming boot2docker and VirtualBox are installed
wget http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso
mv boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso ~/.boot2docker/boot2docker.iso
# blow away your old boot2docker-vm if it exists (boot2docker down && boot2docker destroy)
boot2docker init
boot2docker up
# set DOCKER_HOST as instructed
boot2docker stop
VBoxManage sharedfolder add boot2docker-vm --name /Users --hostpath /Users
boot2docker up
# if you ssh into the VM now, you'll notice /Users is present, but empty; I don't know/care why.
boot2docker ssh "sudo mount -t vboxsf -o uid=1000,gid=50 /Users /Users"
# done

This worked for me so I hope it works for others. In the near future, I expect this issue to be solved by boot2docker, especially since the PR from which I got these commands was merged.

EDIT: boot2docker 1.3.0 supports this without any further changes. After updating, I ran these commands:

boot2docker destroy  # start over
boot2docker download # download the udpated ISO
boot2docker init
boot2docker up
# done

这篇关于在OSX上挂载到Docker映像的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆