Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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.

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?


And I've looked up Vagrant official document

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

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

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...

like image 880
LiJung Avatar asked Nov 20 '13 06:11

LiJung


1 Answers

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

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

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

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

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

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!

like image 185
Geoffrey Bachelet Avatar answered Oct 06 '22 14:10

Geoffrey Bachelet