Intro
I can't figure out a good way to setup a development environment on OS X using Docker and Boot2Docker. The problem I'm hitting is how to manage the source code so that:
我无法找到使用Docker和Boot2Docker在OS X上设置开发环境的好方法。我遇到的问题是如何管理源代码,以便:
- I can modify the code on OS X using the tools (text editor, IDE, git, etc) I already have installed.
- Those modifications are reflected in the Docker container so if I re-run tests or refresh a webpage, I can see my changes immediately.
我可以使用我已安装的工具(文本编辑器,IDE,git等)修改OS X上的代码。
这些修改反映在Docker容器中,因此如果我重新运行测试或刷新网页,我可以立即看到我的更改。
In theory, this should be easy to do by mounting my source code as a volume:
理论上,通过将我的源代码作为卷安装,这应该很容易做到:
docker run -it -v /path/to/my/source/code:/src some-docker-image
Unfortunately, this has two major issues that make it completely unusable on OS X:
不幸的是,这有两个主要问题使它在OS X上完全无法使用:
Issue #1: Mounted volumes on Virtual Box (which use vboxsf) are extremely slow
For example, here is how long it takes Jekyll to compile my homepage if the source code is part of the Docker image:
例如,如果源代码是Docker镜像的一部分,这里是Jekyll编译我的主页需要多长时间:
> docker run -it brikis98/yevgeniy-brikman-homepage:v1 bash
root@7aaea30d98a1:/src# time bundle exec jekyll build
[...]
real 0m7.879s
user 0m7.360s
sys 0m0.600s
Here is the exact same Docker image, except this time, I mount the source code from OS X:
这是完全相同的Docker镜像,除了这次,我从OS X挂载源代码:
> docker run -it -v $(pwd):/src brikis98/yevgeniy-brikman-homepage:v1 bash
root@1521b0b4ce6a:/src# time bundle exec jekyll build
[...]
real 1m14.701s
user 0m9.450s
sys 0m3.410s
Issue #2: File watching is broken
The default watch mechanisms in SBT, Jekyll, and grunt use technologies such as inotify, which do not work if they are running in a Docker container and the changes are made in OS X to a mounted folder.
SBT,Jekyll和grunt中的默认监视机制使用inotify等技术,如果它们在Docker容器中运行并且在OS X中对安装的文件夹进行了更改,则它们不起作用。
Workarounds I tried
I searched for solutions (including all the ones on SO) and tried out a few of them, but have not found a successful one:
我搜索了解决方案(包括SO上的所有解决方案)并尝试了其中一些,但没有找到成功的解决方案:
- I switched Boot2Docker to use NFS, but it was just as slow.
- I tried Vagrant + NFS, and that was also just as slow.
- I tried a Samba mount, but the folder always showed up empty in the Docker container.
- I tried to use the unison file system, which worked briefly to sync files, but then kept showing connection errors.
- I enabled polling in Jekyll, but that significantly increased the delay until my changes were picked up.
- I tried dinghy, a "faster, friendlier Docker on OS X with Vagrant" and got some improvement. Instead of jekyll compilation being 10-15x slower, it was 2-3x slower. That's better, but still not quite usable.
我将Boot2Docker切换为使用NFS,但速度一样慢。
我尝试过Vagrant + NFS,这也很慢。
我尝试了Samba安装,但该文件夹在Docker容器中始终显示为空。
我试图使用unison文件系统,它简单地用于同步文件,但后来一直显示连接错误。
我在Jekyll中启用了轮询,但这显着增加了延迟,直到我的更改被拾取。
我尝试了小艇,一个“在OS X上使用Vagrant更快,更友好的Docker”并得到了一些改进。而不是jekyll编译慢10-15倍,它慢2-3倍。那更好,但仍然不太可用。
Has anyone found a solution that actually works and allows you to productively develop code with Docker and OS X?
有没有人找到一个真正有效的解决方案,并允许您使用Docker和OS X高效地开发代码?
Update: a solution at last!
I have finally found a solution that seems productive using Boot2Docker + rsync. I've captured the details on how to set this up in my own answer as well as an open source project called docker-osx-dev.
我终于找到了一个使用Boot2Docker + rsync看起来很有效的解决方案。我已经在我自己的答案中捕获了有关如何设置它的详细信息,以及一个名为docker-osx-dev的开源项目。
10 个解决方案
#1
I've decided to add my own answer with the best solution I've found so far. I'll update this if I find better options.
我决定用我迄今为止找到的最佳解决方案添加我自己的答案。如果我找到更好的选择,我会更新这个。
Best solution so far
The best solution I've found for setting up a productive development environment with Docker on OS X is: Boot2Docker + Rsync. With rsync, build times in a Docker container are on par with running the build directly on OSX! Moreover, the file watcher code does not need polling (inotify
works since rsync uses normal folders), so hot reload is almost as fast.
我发现在OS X上使用Docker建立高效开发环境的最佳解决方案是:Boot2Docker + Rsync。使用rsync,Docker容器中的构建时间与直接在OSX上运行构建相同!此外,文件观察程序代码不需要轮询(因为rsync使用普通文件夹,因此inotify工作),因此热重载几乎一样快。
There are two ways to set it up: an automated install and a manual install.
有两种设置方法:自动安装和手动安装。
Automated install
I've packaged all the steps for setting up Boot2Docker with Rsync into an open source project called docker-osx-dev. The code is a bit rough, but I've been successfully using it for several weeks to easily switch between 3 projects with 3 different tech stacks. Try it out, report bugs, and submit some PRs! Also, see my blog post, A productive development environment with Docker on OS X for more info.
我已经将使用Rsync设置Boot2Docker的所有步骤打包到一个名为docker-osx-dev的开源项目中。代码有点粗糙,但我已成功使用它几周,可以轻松地在3个项目之间切换3个不同的技术堆栈。尝试一下,报告错误,并提交一些PR!另外,请参阅我的博客文章,在OS X上使用Docker获得更多信息的高效开发环境。
Manual setup
- Install Boot2Docker:
brew install boot2docker
. - Run Boot2Docker, but with VirtualBox shared folders disabled:
boot2docker init && boot2docker start --vbox-share=disable
. - Run
boot2docker shellinit
and copy the environment variables it prints out into your~/.bash_profile
file. - Install rsync on the Boot2Docker VM:
boot2docker ssh "tce-load -wi rsync"
. - Create the base folders you need on the Boot2Docker VM and set permissions correctly for them. For example, if you'll be syncing the
/foo/bar
folder from OS X, you need to create/foo/bar
on the Boot2Docker VM:boot2docker ssh "mkdir -p /foo/bar && chown -R docker /foo/bar"
. - Run rsync to sync the files to the Boot2Docker VM:
rsync --archive --rsh="ssh -i $HOME/.ssh/id_boot2docker -o StrictHostKeyChecking=no" /foo/bar docker@dockerhost:/foo
. Check the rsync docs for various settings you may want to enable, such as using--exclude .git
to exclude the.git
folder when syncing. - Use a file watcher to keep files in sync. For example, you could use fswatch (
brew install fswatch
) piped into rsync. - At this point, you should be able to use
docker run
to fire up your Docker container and use the-v
flag to mount the folder you're syncing:docker run -v /foo/bar:/src some-docker-image
. - Update the code on OS X as usual. Changes should propagate very quickly using rsync, the normal file watcher code should pick up the changes as usual (ie, using
inotify
), and the build should run fast because all the files are "local" to the container. - If you need to test a running website, run the
boot2docker ip
command to find out what IP it's on.
安装Boot2Docker:brew install boot2docker。
运行Boot2Docker,但禁用VirtualBox共享文件夹:boot2docker init && boot2docker start --vbox-share = disable。
运行boot2docker shellinit并将其打印出来的环境变量复制到〜/ .bash_profile文件中。
在Boot2Docker VM上安装rsync:boot2docker ssh“tce-load -wi rsync”。
在Boot2Docker VM上创建所需的基本文件夹,并为它们正确设置权限。例如,如果您要从OS X同步/ foo / bar文件夹,则需要在Boot2Docker VM上创建/ foo / bar:boot2docker ssh“mkdir -p / foo / bar && chown -R docker / foo /酒吧”。
运行rsync将文件同步到Boot2Docker VM:rsync --archive --rsh =“ssh -i $ HOME / .ssh / id_boot2docker -o StrictHostKeyChecking = no”/ foo / bar docker @ dockerhost:/ foo。检查rsync文档以了解您可能要启用的各种设置,例如在同步时使用--exclude .git排除.git文件夹。
使用文件观察器使文件保持同步。例如,你可以使用传递到rsync的fswatch(brew install fswatch)。
此时,您应该能够使用docker run来启动Docker容器并使用-v标志来挂载您正在同步的文件夹:docker run -v / foo / bar:/ src some-docker-image。
像往常一样更新OS X上的代码。更改应使用rsync非常快速地传播,正常的文件观察程序代码应该像往常一样获取更改(即使用inotify),并且构建应该快速运行,因为所有文件都是容器的“本地”。
如果您需要测试正在运行的网站,请运行boot2docker ip命令以查找它所在的IP。
#2
Update: Now that docker for mac is in beta with non-hack functionality, going that route may be a lot more reasonable for local development without a essay's worth of hacks and workarounds.
更新:现在,对于mac的docker处于测试阶段且具有非黑客功能,对于本地开发来说,走这条路线可能更合理,没有文章的价值和解决方法。
Don't. I know that's not the answer you are probably hoping for, but take an honest evaluation of the cost/benefit of trying to get local source code + dockerized execution vs just doing local development on OSX.
别。我知道这不是你可能希望得到的答案,而是对尝试获取本地源代码+ dockerized执行与仅在OSX上进行本地开发的成本/收益进行诚实的评估。
At some point all the issues, setup effort, and operational pain points MAY be resolved well enough, but as of right now my take on this is it's a net loss.
在某些时候,所有问题,设置工作和操作痛点都可以得到很好的解决,但是现在我对此的看法是净损失。
Issue #1: Mounted volumes on Virtual Box (which use vboxfs) are extremely slow
问题#1:Virtual Box上的挂载卷(使用vboxf)非常慢
Wait a while and this will almost certainly improve.
等一会儿,这几乎肯定会有所改善。
Issue #2: File watching is broken
问题#2:文件观看被破坏了
I'm not sure a fix for this is in the near future. If this type of functionality is key to your development workflow, I would consider this a dealbreaker. It's not worth a major R&D effort when compared to just using rbenv/bundler to manage your jekyll/ruby installs and running them locally on OSX like folks have been doing successfully for the past decade+.
我不确定在不久的将来可以解决这个问题。如果这种类型的功能对您的开发工作流程至关重要,我会认为这是一个破解者。与仅仅使用rbenv / bundler管理你的jekyll / ruby安装并在OSX上本地运行它们相比,不值得进行大规模的研发工作,就像人们在过去十年里一直在成功做的那样。
Just like "the cloud" has zero involvement in my local development setup, at the moment, docker is a win for testing/staging/deployment and for running databases and other third party components, but the applications I'm actually coding get run straight on OSX.
就像“云”没有参与我的本地开发设置一样,目前,docker是测试/暂存/部署以及运行数据库和其他第三方组件的胜利,但我实际编码的应用程序直接运行在OSX上。
#3
Docker for Mac and Windows shall be the definitive way of developing with Docker on OS X (and Windows). A Docker product, the software is an “integrated, easy-to-deploy environment for building, assembling, and shipping applications from Mac or Windows.” It purports to be able to solve the issues presented by the OP. From its March 24, 2016 announcement:
适用于Mac和Windows的Docker将是在OS X(和Windows)上使用Docker进行开发的最终方式。作为Docker产品,该软件是一个“集成,易于部署的环境,用于从Mac或Windows构建,组装和运送应用程序。”它旨在解决OP提出的问题。自2016年3月24日公告:
- Faster and more reliable: no more VirtualBox! The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X or on a Hyper-V VM on Windows, and that VM is managed by the Docker application. You don’t need docker-machine to run Docker for Mac and Windows.
- Tools integration: Docker for Mac is a Mac application and Docker for Windows is a Windows application, including a native user interface and auto-update capability. The Docker tool set comes bundled with it: Docker command line, Docker Compose, and Docker Notary command line.
- Volume mounting for your code and data: volume data access works correctly, including file change notifications (on Mac inotify now works seamlessly inside containers for volume mounted directories). This enables edit/test cycles for “in container” development.
- Easy access to running containers on the local host network: Docker for Mac and Windows include a DNS server for containers, and are integrated with the Mac OS X and Windows networking system. On a Mac, Docker can be used even when connected to a very restrictive corporate VPN.
- Docker for Mac was architected from scratch to be able to fit the OS X sandbox security model and we are working closely with Apple to achieve this.
更快更可靠:不再需要VirtualBox! Docker引擎在Mac OS X上的xhyve虚拟机或Windows上的Hyper-V VM上运行在Alpine Linux发行版中,该VM由Docker应用程序管理。您不需要docker-machine来运行Docker for Mac和Windows。
工具集成:Docker for Mac是Mac应用程序,Docker for Windows是Windows应用程序,包括本机用户界面和自动更新功能。 Docker工具集与它捆绑在一起:Docker命令行,Docker Compose和Docker Notary命令行。
代码和数据的卷安装:卷数据访问正常工作,包括文件更改通知(在Mac上,inotify现在可以无缝地在卷装入目录的容器内工作)。这使得“容器”开发的编辑/测试周期成为可能。
轻松访问本地主机网络上正在运行的容器:适用于Mac和Windows的Docker包括用于容器的DNS服务器,并与Mac OS X和Windows网络系统集成。在Mac上,即使连接到限制性很强的企业VPN,也可以使用Docker。
Docker for Mac从头开始构建,能够适应OS X沙箱安全模型,我们正在与Apple密切合作以实现这一目标。
#4
Disclaimer: I might be biased, since I am the author of docker-sync.
免责声明:我可能有偏见,因为我是docker-sync的作者。
I probably tried all the solutions named here, including some more (see the compersion https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync), but they basically either failed on the side of performance (most of them) or on the docker-machine (or none) used / enforced.
我可能尝试了这里命名的所有解决方案,包括更多(请参阅compersion https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync),但他们基本上都失败了性能(大多数)或在docker-machine(或none)上使用/强制执行。
http://docker-sync.io has been built to merge all the solutions and provide the best strategies (implementing several, you can choose).
http://docker-sync.io已经构建为合并所有解决方案并提供最佳策略(实现几个,您可以选择)。
It can be used with rsync (1 way sync) including permission fixes for users, and with unison (2 way sync). It does neither force you into docker-machine or a specific hypervisor, nor requires you to have docker for Mac. It works with all of them.
它可以与rsync(单向同步)一起使用,包括用户的权限修复,以及unison(双向同步)。它既不会强迫你进入docker-machine或特定的hypervisor,也不要求你拥有适用于Mac的docker。它适用于所有这些。
The performance EugenMayer/docker-sync/wiki/4.-Performance is not influenced, it's like you have no shares at all.
性能EugenMayer / docker-sync / wiki / 4.-Performance不受影响,就像你根本就没有共享一样。
docker-sync and its change-watchers are optimized and do work with projects with 12k files without issues.
docker-sync及其变更监视器已经过优化,可以处理12k文件没有问题的项目。
Give it a try, if you like, I would love to hear feedback!
试一试,如果你愿意,我很乐意听到反馈!
#5
I feel you! I think I've tried pretty much everything you tried and unfortunately it was still slow. Then I came across this comment https://github.com/boot2docker/boot2docker/issues/64#issuecomment-70689254 that suggests using Vagrant and Parallels and instead of Virtualbox. This allowed me to use nfs and I did indeed saw a big performance boost for my project (Drupal).
我感觉到你了!我想我已经尝试过你尝试过的所有东西,不幸的是它仍然很慢。然后我发现了这个评论https://github.com/boot2docker/boot2docker/issues/64#issuecomment-70689254,建议使用Vagrant和Parallels而不是Virtualbox。这让我可以使用nfs,我确实看到了我的项目(Drupal)的巨大性能提升。
Here's the Vagrant file. All you need to do is install vagrant, copy this in a file called Vagrantfile and put it in some folder. Go to that folder and just do a vagrant up
instead of your normal boot2docker up.
这是Vagrant文件。您需要做的就是安装vagrant,将其复制到名为Vagrantfile的文件中并将其放在某个文件夹中。转到那个文件夹,然后做一个流浪汉,而不是你正常的boot2docker。
Vagrant.configure(2) do |config|
config.vm.box = "parallels/boot2docker"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.synced_folder(
"/Users/dicix/work/www", "/vagrant",
type: 'nfs',
nfs_udp: true,
mount_options: %w[actimeo=2],
bsd__nfs_options: %w[alldirs maproot=root:wheel]
)
end
#6
I'm also using Vagrant with parallels and boot2docker (https://github.com/Parallels/boot2docker-vagrant-box). Development was never easier for me. Works really well with docker-compose
and large setups. I don't really feel a delay or massive resource consumption.
我也在使用Vagrant和parallels以及boot2docker(https://github.com/Parallels/boot2docker-vagrant-box)。发展对我来说从未如此简单。与docker-compose和大型设置配合得非常好。我真的没有感觉到延迟或大量的资源消耗。
This is what my Vagrantfile
looks like:
这就是我的Vagrantfile的样子:
Vagrant.configure(2) do |config|
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.box = "parallels/boot2docker"
config.vm.synced_folder "/Users", "/Users", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync"
end
#7
I've been developing in a OS X (mid 2011 Macbook Air) + Boot2Docker + Docker-compose environment for a few weeks now. Haven't run into major performance issues but I avoid running any sort of build when developing (why not use something like jekyll serve --skip-initial-build
?). Here's an example docker-compose.yml
file I'm using:
我已经在OS X(2011年中期Macbook Air)和Boot2Docker + Docker组合环境中开发了几周。没有遇到主要的性能问题,但我在开发时避免运行任何类型的构建(为什么不使用像jekyll serve -skip-initial-build?这样的东西)。这是我正在使用的docker-compose.yml文件示例:
docker-compose.yml:
test:
build: .
volumes:
- ./client:/src/client
- ./server:/src/server
- ./test:/src/test
command: nodemon --exec jasmine-node -- test/ --verbose --autotest --captureExceptions --color
environment:
- DEBUG=*
Dockerfile:
FROM node:0.12
RUN mkdir -p /src
WORKDIR /src
ENV PATH=/src/node_modules/.bin:$PATH
# We add package.json first so that we the
# image build can use the cache as long as the
# contents of package.json hasn't changed.
COPY package.json /src/
RUN npm install --unsafe-perm
COPY . /src
CMD [ "npm", "start" ]
EXPOSE 3000
I sometimes use NFS (http://syskall.com/using-boot2docker-using-nfs-instead-of-vboxsf/) but haven't noticed a big performance difference when doing so.
我有时使用NFS(http://syskall.com/using-boot2docker-using-nfs-instead-of-vboxsf/),但在这样做时没有注意到性能差异很大。
For me, the convenience of a simple docker-compose up test
to get my environment running has been worth the cost in performance (I routinely work on multiple projects with different stacks).
对我来说,简单的docker组合测试以便让我的环境运行的便利性是值得的性能成本(我经常处理具有不同堆栈的多个项目)。
PS: nodemon
is one of the few file watchers which work with vboxsf (see https://github.com/remy/nodemon/issues/419).
PS:nodemon是少数与vboxsf一起使用的文件监视器之一(参见https://github.com/remy/nodemon/issues/419)。
#8
Docker Unison works like a charm! https://github.com/leighmcculloch/docker-unison
Docker Unison就像一个魅力! https://github.com/leighmcculloch/docker-unison
Bidirectional Sync with a very good performance!
双向同步具有非常好的性能!
#9
Getting docker to work as a development tool is possible. But its going to hurt. I've documented the process here :
让docker作为开发工具工作是可能的。但它会受到伤害。我在这里记录了这个过程:
http://harmingcola.blogspot.com/2015/05/how-to-setup-docker-as-development-tool.html
#10
This method is the latest (Sep 2015) and easiest way to get Docker setup on Mac: link here:
这种方法是最新的(2015年9月)和最简单的在Mac上安装Docker的方法:链接在这里:
You install Docker using Docker Toolbox link to instructions here:
您可以使用Docker Toolbox链接将Docker安装到此处的说明:
It is a complete Docker setup package, that includes the following Docker tools:
它是一个完整的Docker安装包,包括以下Docker工具:
Docker Machine for running the docker-machine binary
用于运行docker-machine二进制文件的Docker Machine
Docker Engine for running the docker binary
用于运行docker二进制文件的Docker Engine
Docker Compose for running the docker-compose binary
Docker Compose用于运行docker-compose二进制文件
Kitematic, the Docker GUI a shell preconfigured for a Docker command-line environment
Kitematic,Docker GUI是为Docker命令行环境预配置的shell
Oracle VM VirtualBox
Oracle VM VirtualBox
What's in the toolbox:
- Docker Client
- Docker Machine
- Docker Compose (Mac only)
- Docker Kitematic
- VirtualBox
Docker Compose(仅适用于Mac)
#1
I've decided to add my own answer with the best solution I've found so far. I'll update this if I find better options.
我决定用我迄今为止找到的最佳解决方案添加我自己的答案。如果我找到更好的选择,我会更新这个。
Best solution so far
The best solution I've found for setting up a productive development environment with Docker on OS X is: Boot2Docker + Rsync. With rsync, build times in a Docker container are on par with running the build directly on OSX! Moreover, the file watcher code does not need polling (inotify
works since rsync uses normal folders), so hot reload is almost as fast.
我发现在OS X上使用Docker建立高效开发环境的最佳解决方案是:Boot2Docker + Rsync。使用rsync,Docker容器中的构建时间与直接在OSX上运行构建相同!此外,文件观察程序代码不需要轮询(因为rsync使用普通文件夹,因此inotify工作),因此热重载几乎一样快。
There are two ways to set it up: an automated install and a manual install.
有两种设置方法:自动安装和手动安装。
Automated install
I've packaged all the steps for setting up Boot2Docker with Rsync into an open source project called docker-osx-dev. The code is a bit rough, but I've been successfully using it for several weeks to easily switch between 3 projects with 3 different tech stacks. Try it out, report bugs, and submit some PRs! Also, see my blog post, A productive development environment with Docker on OS X for more info.
我已经将使用Rsync设置Boot2Docker的所有步骤打包到一个名为docker-osx-dev的开源项目中。代码有点粗糙,但我已成功使用它几周,可以轻松地在3个项目之间切换3个不同的技术堆栈。尝试一下,报告错误,并提交一些PR!另外,请参阅我的博客文章,在OS X上使用Docker获得更多信息的高效开发环境。
Manual setup
- Install Boot2Docker:
brew install boot2docker
. - Run Boot2Docker, but with VirtualBox shared folders disabled:
boot2docker init && boot2docker start --vbox-share=disable
. - Run
boot2docker shellinit
and copy the environment variables it prints out into your~/.bash_profile
file. - Install rsync on the Boot2Docker VM:
boot2docker ssh "tce-load -wi rsync"
. - Create the base folders you need on the Boot2Docker VM and set permissions correctly for them. For example, if you'll be syncing the
/foo/bar
folder from OS X, you need to create/foo/bar
on the Boot2Docker VM:boot2docker ssh "mkdir -p /foo/bar && chown -R docker /foo/bar"
. - Run rsync to sync the files to the Boot2Docker VM:
rsync --archive --rsh="ssh -i $HOME/.ssh/id_boot2docker -o StrictHostKeyChecking=no" /foo/bar docker@dockerhost:/foo
. Check the rsync docs for various settings you may want to enable, such as using--exclude .git
to exclude the.git
folder when syncing. - Use a file watcher to keep files in sync. For example, you could use fswatch (
brew install fswatch
) piped into rsync. - At this point, you should be able to use
docker run
to fire up your Docker container and use the-v
flag to mount the folder you're syncing:docker run -v /foo/bar:/src some-docker-image
. - Update the code on OS X as usual. Changes should propagate very quickly using rsync, the normal file watcher code should pick up the changes as usual (ie, using
inotify
), and the build should run fast because all the files are "local" to the container. - If you need to test a running website, run the
boot2docker ip
command to find out what IP it's on.
安装Boot2Docker:brew install boot2docker。
运行Boot2Docker,但禁用VirtualBox共享文件夹:boot2docker init && boot2docker start --vbox-share = disable。
运行boot2docker shellinit并将其打印出来的环境变量复制到〜/ .bash_profile文件中。
在Boot2Docker VM上安装rsync:boot2docker ssh“tce-load -wi rsync”。
在Boot2Docker VM上创建所需的基本文件夹,并为它们正确设置权限。例如,如果您要从OS X同步/ foo / bar文件夹,则需要在Boot2Docker VM上创建/ foo / bar:boot2docker ssh“mkdir -p / foo / bar && chown -R docker / foo /酒吧”。
运行rsync将文件同步到Boot2Docker VM:rsync --archive --rsh =“ssh -i $ HOME / .ssh / id_boot2docker -o StrictHostKeyChecking = no”/ foo / bar docker @ dockerhost:/ foo。检查rsync文档以了解您可能要启用的各种设置,例如在同步时使用--exclude .git排除.git文件夹。
使用文件观察器使文件保持同步。例如,你可以使用传递到rsync的fswatch(brew install fswatch)。
此时,您应该能够使用docker run来启动Docker容器并使用-v标志来挂载您正在同步的文件夹:docker run -v / foo / bar:/ src some-docker-image。
像往常一样更新OS X上的代码。更改应使用rsync非常快速地传播,正常的文件观察程序代码应该像往常一样获取更改(即使用inotify),并且构建应该快速运行,因为所有文件都是容器的“本地”。
如果您需要测试正在运行的网站,请运行boot2docker ip命令以查找它所在的IP。
#2
Update: Now that docker for mac is in beta with non-hack functionality, going that route may be a lot more reasonable for local development without a essay's worth of hacks and workarounds.
更新:现在,对于mac的docker处于测试阶段且具有非黑客功能,对于本地开发来说,走这条路线可能更合理,没有文章的价值和解决方法。
Don't. I know that's not the answer you are probably hoping for, but take an honest evaluation of the cost/benefit of trying to get local source code + dockerized execution vs just doing local development on OSX.
别。我知道这不是你可能希望得到的答案,而是对尝试获取本地源代码+ dockerized执行与仅在OSX上进行本地开发的成本/收益进行诚实的评估。
At some point all the issues, setup effort, and operational pain points MAY be resolved well enough, but as of right now my take on this is it's a net loss.
在某些时候,所有问题,设置工作和操作痛点都可以得到很好的解决,但是现在我对此的看法是净损失。
Issue #1: Mounted volumes on Virtual Box (which use vboxfs) are extremely slow
问题#1:Virtual Box上的挂载卷(使用vboxf)非常慢
Wait a while and this will almost certainly improve.
等一会儿,这几乎肯定会有所改善。
Issue #2: File watching is broken
问题#2:文件观看被破坏了
I'm not sure a fix for this is in the near future. If this type of functionality is key to your development workflow, I would consider this a dealbreaker. It's not worth a major R&D effort when compared to just using rbenv/bundler to manage your jekyll/ruby installs and running them locally on OSX like folks have been doing successfully for the past decade+.
我不确定在不久的将来可以解决这个问题。如果这种类型的功能对您的开发工作流程至关重要,我会认为这是一个破解者。与仅仅使用rbenv / bundler管理你的jekyll / ruby安装并在OSX上本地运行它们相比,不值得进行大规模的研发工作,就像人们在过去十年里一直在成功做的那样。
Just like "the cloud" has zero involvement in my local development setup, at the moment, docker is a win for testing/staging/deployment and for running databases and other third party components, but the applications I'm actually coding get run straight on OSX.
就像“云”没有参与我的本地开发设置一样,目前,docker是测试/暂存/部署以及运行数据库和其他第三方组件的胜利,但我实际编码的应用程序直接运行在OSX上。
#3
Docker for Mac and Windows shall be the definitive way of developing with Docker on OS X (and Windows). A Docker product, the software is an “integrated, easy-to-deploy environment for building, assembling, and shipping applications from Mac or Windows.” It purports to be able to solve the issues presented by the OP. From its March 24, 2016 announcement:
适用于Mac和Windows的Docker将是在OS X(和Windows)上使用Docker进行开发的最终方式。作为Docker产品,该软件是一个“集成,易于部署的环境,用于从Mac或Windows构建,组装和运送应用程序。”它旨在解决OP提出的问题。自2016年3月24日公告:
- Faster and more reliable: no more VirtualBox! The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X or on a Hyper-V VM on Windows, and that VM is managed by the Docker application. You don’t need docker-machine to run Docker for Mac and Windows.
- Tools integration: Docker for Mac is a Mac application and Docker for Windows is a Windows application, including a native user interface and auto-update capability. The Docker tool set comes bundled with it: Docker command line, Docker Compose, and Docker Notary command line.
- Volume mounting for your code and data: volume data access works correctly, including file change notifications (on Mac inotify now works seamlessly inside containers for volume mounted directories). This enables edit/test cycles for “in container” development.
- Easy access to running containers on the local host network: Docker for Mac and Windows include a DNS server for containers, and are integrated with the Mac OS X and Windows networking system. On a Mac, Docker can be used even when connected to a very restrictive corporate VPN.
- Docker for Mac was architected from scratch to be able to fit the OS X sandbox security model and we are working closely with Apple to achieve this.
更快更可靠:不再需要VirtualBox! Docker引擎在Mac OS X上的xhyve虚拟机或Windows上的Hyper-V VM上运行在Alpine Linux发行版中,该VM由Docker应用程序管理。您不需要docker-machine来运行Docker for Mac和Windows。
工具集成:Docker for Mac是Mac应用程序,Docker for Windows是Windows应用程序,包括本机用户界面和自动更新功能。 Docker工具集与它捆绑在一起:Docker命令行,Docker Compose和Docker Notary命令行。
代码和数据的卷安装:卷数据访问正常工作,包括文件更改通知(在Mac上,inotify现在可以无缝地在卷装入目录的容器内工作)。这使得“容器”开发的编辑/测试周期成为可能。
轻松访问本地主机网络上正在运行的容器:适用于Mac和Windows的Docker包括用于容器的DNS服务器,并与Mac OS X和Windows网络系统集成。在Mac上,即使连接到限制性很强的企业VPN,也可以使用Docker。
Docker for Mac从头开始构建,能够适应OS X沙箱安全模型,我们正在与Apple密切合作以实现这一目标。
#4
Disclaimer: I might be biased, since I am the author of docker-sync.
免责声明:我可能有偏见,因为我是docker-sync的作者。
I probably tried all the solutions named here, including some more (see the compersion https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync), but they basically either failed on the side of performance (most of them) or on the docker-machine (or none) used / enforced.
我可能尝试了这里命名的所有解决方案,包括更多(请参阅compersion https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync),但他们基本上都失败了性能(大多数)或在docker-machine(或none)上使用/强制执行。
http://docker-sync.io has been built to merge all the solutions and provide the best strategies (implementing several, you can choose).
http://docker-sync.io已经构建为合并所有解决方案并提供最佳策略(实现几个,您可以选择)。
It can be used with rsync (1 way sync) including permission fixes for users, and with unison (2 way sync). It does neither force you into docker-machine or a specific hypervisor, nor requires you to have docker for Mac. It works with all of them.
它可以与rsync(单向同步)一起使用,包括用户的权限修复,以及unison(双向同步)。它既不会强迫你进入docker-machine或特定的hypervisor,也不要求你拥有适用于Mac的docker。它适用于所有这些。
The performance EugenMayer/docker-sync/wiki/4.-Performance is not influenced, it's like you have no shares at all.
性能EugenMayer / docker-sync / wiki / 4.-Performance不受影响,就像你根本就没有共享一样。
docker-sync and its change-watchers are optimized and do work with projects with 12k files without issues.
docker-sync及其变更监视器已经过优化,可以处理12k文件没有问题的项目。
Give it a try, if you like, I would love to hear feedback!
试一试,如果你愿意,我很乐意听到反馈!
#5
I feel you! I think I've tried pretty much everything you tried and unfortunately it was still slow. Then I came across this comment https://github.com/boot2docker/boot2docker/issues/64#issuecomment-70689254 that suggests using Vagrant and Parallels and instead of Virtualbox. This allowed me to use nfs and I did indeed saw a big performance boost for my project (Drupal).
我感觉到你了!我想我已经尝试过你尝试过的所有东西,不幸的是它仍然很慢。然后我发现了这个评论https://github.com/boot2docker/boot2docker/issues/64#issuecomment-70689254,建议使用Vagrant和Parallels而不是Virtualbox。这让我可以使用nfs,我确实看到了我的项目(Drupal)的巨大性能提升。
Here's the Vagrant file. All you need to do is install vagrant, copy this in a file called Vagrantfile and put it in some folder. Go to that folder and just do a vagrant up
instead of your normal boot2docker up.
这是Vagrant文件。您需要做的就是安装vagrant,将其复制到名为Vagrantfile的文件中并将其放在某个文件夹中。转到那个文件夹,然后做一个流浪汉,而不是你正常的boot2docker。
Vagrant.configure(2) do |config|
config.vm.box = "parallels/boot2docker"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.synced_folder(
"/Users/dicix/work/www", "/vagrant",
type: 'nfs',
nfs_udp: true,
mount_options: %w[actimeo=2],
bsd__nfs_options: %w[alldirs maproot=root:wheel]
)
end
#6
I'm also using Vagrant with parallels and boot2docker (https://github.com/Parallels/boot2docker-vagrant-box). Development was never easier for me. Works really well with docker-compose
and large setups. I don't really feel a delay or massive resource consumption.
我也在使用Vagrant和parallels以及boot2docker(https://github.com/Parallels/boot2docker-vagrant-box)。发展对我来说从未如此简单。与docker-compose和大型设置配合得非常好。我真的没有感觉到延迟或大量的资源消耗。
This is what my Vagrantfile
looks like:
这就是我的Vagrantfile的样子:
Vagrant.configure(2) do |config|
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.box = "parallels/boot2docker"
config.vm.synced_folder "/Users", "/Users", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync"
end
#7
I've been developing in a OS X (mid 2011 Macbook Air) + Boot2Docker + Docker-compose environment for a few weeks now. Haven't run into major performance issues but I avoid running any sort of build when developing (why not use something like jekyll serve --skip-initial-build
?). Here's an example docker-compose.yml
file I'm using:
我已经在OS X(2011年中期Macbook Air)和Boot2Docker + Docker组合环境中开发了几周。没有遇到主要的性能问题,但我在开发时避免运行任何类型的构建(为什么不使用像jekyll serve -skip-initial-build?这样的东西)。这是我正在使用的docker-compose.yml文件示例:
docker-compose.yml:
test:
build: .
volumes:
- ./client:/src/client
- ./server:/src/server
- ./test:/src/test
command: nodemon --exec jasmine-node -- test/ --verbose --autotest --captureExceptions --color
environment:
- DEBUG=*
Dockerfile:
FROM node:0.12
RUN mkdir -p /src
WORKDIR /src
ENV PATH=/src/node_modules/.bin:$PATH
# We add package.json first so that we the
# image build can use the cache as long as the
# contents of package.json hasn't changed.
COPY package.json /src/
RUN npm install --unsafe-perm
COPY . /src
CMD [ "npm", "start" ]
EXPOSE 3000
I sometimes use NFS (http://syskall.com/using-boot2docker-using-nfs-instead-of-vboxsf/) but haven't noticed a big performance difference when doing so.
我有时使用NFS(http://syskall.com/using-boot2docker-using-nfs-instead-of-vboxsf/),但在这样做时没有注意到性能差异很大。
For me, the convenience of a simple docker-compose up test
to get my environment running has been worth the cost in performance (I routinely work on multiple projects with different stacks).
对我来说,简单的docker组合测试以便让我的环境运行的便利性是值得的性能成本(我经常处理具有不同堆栈的多个项目)。
PS: nodemon
is one of the few file watchers which work with vboxsf (see https://github.com/remy/nodemon/issues/419).
PS:nodemon是少数与vboxsf一起使用的文件监视器之一(参见https://github.com/remy/nodemon/issues/419)。
#8
Docker Unison works like a charm! https://github.com/leighmcculloch/docker-unison
Docker Unison就像一个魅力! https://github.com/leighmcculloch/docker-unison
Bidirectional Sync with a very good performance!
双向同步具有非常好的性能!
#9
Getting docker to work as a development tool is possible. But its going to hurt. I've documented the process here :
让docker作为开发工具工作是可能的。但它会受到伤害。我在这里记录了这个过程:
http://harmingcola.blogspot.com/2015/05/how-to-setup-docker-as-development-tool.html
#10
This method is the latest (Sep 2015) and easiest way to get Docker setup on Mac: link here:
这种方法是最新的(2015年9月)和最简单的在Mac上安装Docker的方法:链接在这里:
You install Docker using Docker Toolbox link to instructions here:
您可以使用Docker Toolbox链接将Docker安装到此处的说明:
It is a complete Docker setup package, that includes the following Docker tools:
它是一个完整的Docker安装包,包括以下Docker工具:
Docker Machine for running the docker-machine binary
用于运行docker-machine二进制文件的Docker Machine
Docker Engine for running the docker binary
用于运行docker二进制文件的Docker Engine
Docker Compose for running the docker-compose binary
Docker Compose用于运行docker-compose二进制文件
Kitematic, the Docker GUI a shell preconfigured for a Docker command-line environment
Kitematic,Docker GUI是为Docker命令行环境预配置的shell
Oracle VM VirtualBox
Oracle VM VirtualBox
What's in the toolbox:
- Docker Client
- Docker Machine
- Docker Compose (Mac only)
- Docker Kitematic
- VirtualBox
Docker Compose(仅适用于Mac)