在Docker与Vagrant(在Mac上)使用编辑器编辑文件 [英] Editing files using editors in Docker with Vagrant (on Mac)

查看:224
本文介绍了在Docker与Vagrant(在Mac上)使用编辑器编辑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Vagrant的Docker中,使用升华或其他编辑器编辑文件的最佳方式是什么?

What is the best way for me to edit a file using sublime or other editors in Docker with Vagrant?

我正在Mac OSX环境中工作,我已经按照Docker官方文档中的步骤操作。

I'm working on Mac OSX environment, and I've followed the steps on Docker's official document.

http://docs.docker.io/en/latest/installation/vagrant/

git clone https://github.com/dotcloud/docker.git
cd docker
vagrant up

似乎我必须在停泊环境中使用docker(在Mac Docker安装)。所以这使我无法用我的崇高的编辑器编辑我的文件。

It seems like I've to use docker inside vagrant environment (on Mac Docker installation). So this makes me unable to edit my files with my sublime editor.

所以我怎么能用原始的 bash (在Vagrant和Docker环境之外),还是我必须在vagrant上重新设置所有环境才能实现?

so how could I get to edit my files with original bash (outside Vagrant and Docker environment), or did I have to set up all the environment again on vagrant to achieve it?

我查了Vagrant官方文件

And I've looked up Vagrant official document

http://docs.vagrantup.com/v2/getting-started/up.html

's ssh to vagrant environment vagrant ssh ,转到 cd / vagrant / 并创建一个文件。

after I've ssh to vagrant environment vagrant ssh, go to cd /vagrant/ and create a file.

应该在Docker仓库的根目录中,我已经启动了Vagrant,不是吗?但是我找不到它...

It should be in root of the docker repository where I've started up my Vagrant, isn't it? But I can't find it...

推荐答案

代码必须在你的电脑上,一直分享到码头这实际上很容易做到。

The code has to be on your computer, and shared down all the way to docker. This is actually pretty easy to do.

首先你需要分享这些代码。这是在Vagrantfile中使用 synced_folder 选项完成的。例如,如果您的代码位于 / Users / LiJung / code / 中,您可以尝试以下方式:

First you need to share the code to vagrant. This is done in the Vagrantfile, using the synced_folder option. For example, if your code is in /Users/LiJung/code/, you can try something like:

config.vm.synced_folder "/Users/LiJung/app", "/app", :nfs => true

我们使用NFS,因为在主机和VM(vboxfs)之间共享文件夹的默认方式是可疑的

We use NFS because the default way of sharing folders between host and VM (vboxfs) is dubious at best.

这将使您的代码在VM内的 / app 文件夹中可用。

This will make your code available in the /app folder inside the VM.

接下来,您要使用 -v 选项运行容器并挂载外部卷:

Next you want to run a container and mount an external volume into it, using the -v option:

docker run -i -t -v /app:/app <yourcontainer> /bin/bash

这将运行一个容器并挂载 / app 文件夹到容器的 / app 文件夹。

This will run a container and mount the /app folder of the VM to the /app folder of the container.

你现在可以享受您最喜欢的编辑的舒适!

You can now enjoy the comfort of your favorite editor!

这篇关于在Docker与Vagrant(在Mac上)使用编辑器编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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