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

后端 未结 3 1162
生来不讨喜
生来不讨喜 2021-02-08 17:19

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 D

相关标签:
3条回答
  • 2021-02-08 17:54

    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!

    0 讨论(0)
  • 2021-02-08 18:04

    You are not alone on this issue although it might be hard to reproduce. You can see it reported on this pull request and this question here at Stack Overflow (with possible workaround). When I had this issue, I just restarted the virtual machine and the files showed up on the /vagrant folder.

    0 讨论(0)
  • 2021-02-08 18:15

    You have to mount the host volume into boot2docker vagrant vm first, and then, mount the vm volume into your container, more info at http://felipejfc.com/2014/08/29/vagrant_docker_sync_folder/

    0 讨论(0)
提交回复
热议问题