Editing files with editors in Docker using Vagrant (on Mac)

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

I am working on a Mac OSX environment and I have been following the actions of the Docker white paper.

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

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

It seems that I should use docker inside the firewall (when installing Mac Docker). Thus, this does not allow me to edit my files using my sublime editor.

so how can I get to edit my files with the original bash (outside the Vagrant and Docker environments), or did I have to configure the whole environment for vagrants again to achieve this?


And I looked at the Vagrant whitepaper

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

after I have ssh for the vagrant ssh roaming environment, go to cd /vagrant/ and create a file.

It should be at the root of the docker repository where I started my tramp, right? But I can not find it ...

+8
docker vagrant macos
source share
3 answers

The code must be on your computer and transferred to all the docker. This is actually pretty easy to do.

First you need to split the code with the tramp. This is done in the Vagrantfile using the synced_folder parameter. 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 

We use NFS, because the default way to exchange folders between the host and the virtual machine (vboxfs) is dubious at best.

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

Next, you want to start the container and connect an external volume to it using the -v option:

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

This will launch the container and mount the /app folder of the virtual machine into the /app folder of the container.

Now you can enjoy the comfort of your favorite editor!

+8
source share

You are not alone in this matter, although it can be difficult to reproduce. You can see how this was reported on this stretch request and this question is here on stack overflow (with a possible workaround). When I had this problem, I just restarted the virtual machine and the files appeared in the /vagrant folder.

0
source share

First you must mount the host file in boot2docker vagrant vm, and then mount the vm volume in your container, more information at http://felipejfc.com/2014/08/29/vagrant_docker_sync_folder/

0
source share

All Articles