简体   繁体   中英

How to access host OS files from docker container via virtualbox on Windows 10 home

I installed the Docker Toolbox on my Windows 10 home machine. When I hit the quickstart icon, I get a bash shell, and I can run a command like

> docker run -it ruby /bin/bash

That puts me into the bash shell of the docker Ruby container. That container is running on a VirtualBox VM created by the Docker Toolbox. The VM had a shared folder setting with:

Folder Path:  \\?\C:\Users
Folder Name:  c/Users

read-only:  unchecked
auto mount:  checked
make permanent: checked

I would like to be able to access the C:\\Users\\ folder on my Windows 10 host from my docker container via a directory called /code within the container (which is running Debian Jessie).

How can I configure my VM, or my Docker container to be able to access that folder from my docker container?

The key was figuring out how to express the shared volume which traversed the Windows-VirtualBox boundary, and the VirtualBox-Docker boundary.

Since the shared folder between the VirtualBox VM and Windows 10 home is C:\\Users, the mount must be somewhere under that folder tree.

  1. I created a folder in windows called C:\\Users\\Jay\\MyApp. This will be visible inside the VirtualBox VM.
  2. I then decided to call the folder c/MyApp in the Docker container.

The other key point is that the volume mount must start with "//". So the full docker command is:

docker run -it -v //c/Users/Jay/MyApp:/c/MyApp ruby /bin/bash

I can edit the file called C:\\Users\\Jay\\MyApp\\test.rb in Windows, using a nice text editor, and then run it in my Ruby Linux container as

root@ad1e3223e3c7:/# cd c/MyApp
root@ad1e3223e3c7:/c/MyApp# ruby test.rb

The output of test.rb appears on the console of the Docker container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM