What's the best way to share files from Windows to Boot2docker VM?

前端 未结 5 1591
深忆病人
深忆病人 2020-12-02 08:51

I have make my code ready on Windows, but I find it\'s not easy to share to boot2docker.

I also find that boot2docker can\'t persistent my changes. For example, I cr

5条回答
  •  忘掉有多难
    2020-12-02 09:14

    Boot2Docker is a small Linux VM running on VirtualBox. So before you can use your files (from Windows) in Docker (which is running in this VM), you must first share your code with the Boot2Docker VM itself.

    To do so, you mount your Windows folder to the VM when it is shutdown (here a VM name of default is assumed):

    C:/Program Files/Oracle/VirtualBox/VBoxManage sharedfolder \
    add default -name win_share -hostpath c:/work
    

    (Alternatively you can also open the VirtualBox UI and mount the folder to your VM just as you did in your screenshot!)

    Now ssh into the Boot2Docker VM for the Docker Quickstart Terminal:

    docker-machine ssh default

    Then perform the mount:

    1. Make a folder inside the VM: sudo mkdir /VM_share
    2. Mount the Windows folder to it: sudo mount -t vboxsf win_share /VM_share

    After that, you can access C:/work inside your Boot2Docker VM:

    cd /VM_share
    

    Now that your code is present inside your VM, you can use it with Docker, either by mounting it as a volume to the container:

    docker-machine ssh default
    docker run --volume /VM_share:/folder/in/container some/image
    

    Or by using it while building your Docker image:

    ...
    ADD /my_windows_folder /folder
    ...
    

提交回复
热议问题