Shared folders on VirtualBox driver does not work #1814

Closed
onbjerg opened this Issue Sep 6, 2015 · 20 comments

Comments

Projects
None yet
@onbjerg

onbjerg commented Sep 6, 2015

I am using Windows 10 with the latest testbuild of VirtualBox. I can spin up a machine and everything works, except that I can't share new folders with the machine.

My projects all reside on a different drive (D:), and one of the following things always happen:

  1. The machine creates the folders, but it doesn't sync either way
  2. Nothing happens. No folders are created or anything.

This is how I add shared folders:

  1. Turn off the machine with docker-machine stop dev
  2. Add the shared folder through VirtualBox GUI. I make sure it automounts and is permanent.
  3. Start up the machine again.

Versions
VirtualBox: 5.0.3 r102467
Docker Toolbox: 1.8.1c
Windows 10 Pro

@ehazlett

This comment has been minimized.

Show comment
Hide comment
@ehazlett

ehazlett Sep 9, 2015

Member

By default, Machine will only share your home directory. If you want to add more, you need to add them using the VirtualBox UI.

Member

ehazlett commented Sep 9, 2015

By default, Machine will only share your home directory. If you want to add more, you need to add them using the VirtualBox UI.

@ehazlett ehazlett closed this Sep 9, 2015

@onbjerg

This comment has been minimized.

Show comment
Hide comment
@onbjerg

onbjerg Sep 9, 2015

@ehazlett If you read my issue, I did exactly that. It did not work.

onbjerg commented Sep 9, 2015

@ehazlett If you read my issue, I did exactly that. It did not work.

@nathanleclaire

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Sep 9, 2015

Contributor

@onbjerg The shares are probably not mounted when the VM boots. There is an additional step to run a command like sudo mount -t vboxsf sharename /path after the VM boots. I wouldn't count on auto-mounting- historically there have been some complications with boot2docker (the OS) which prevent it from working.

Contributor

nathanleclaire commented Sep 9, 2015

@onbjerg The shares are probably not mounted when the VM boots. There is an additional step to run a command like sudo mount -t vboxsf sharename /path after the VM boots. I wouldn't count on auto-mounting- historically there have been some complications with boot2docker (the OS) which prevent it from working.

@onbjerg

This comment has been minimized.

Show comment
Hide comment
@onbjerg

onbjerg Sep 10, 2015

Okay, that worked. Thanks @nathanleclaire!

onbjerg commented Sep 10, 2015

Okay, that worked. Thanks @nathanleclaire!

@nathanleclaire

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Sep 10, 2015

Contributor

You're welcome!

Contributor

nathanleclaire commented Sep 10, 2015

You're welcome!

@juharris

This comment has been minimized.

Show comment
Hide comment
@juharris

juharris Oct 31, 2015

Those still having trouble may find this post helpful. It details how to add the shared folder in the VirtualBox UI, create the directory in the VM (using mkdir), then how to mount it.

Here's what I did to set up the mount after adding it in the VirtualBox UI:

# Note the extra / at the beginning of the path because of msys/MinGW.
docker-machine.exe ssh default 'sudo mkdir --parents //e/Documents/workspace'
docker-machine.exe ssh default 'sudo mount -t vboxsf e/Documents/workspace //e/Documents/workspace'

It's convenient to do it that way because those commands will stay in your history even if you destroy the VM.

Those still having trouble may find this post helpful. It details how to add the shared folder in the VirtualBox UI, create the directory in the VM (using mkdir), then how to mount it.

Here's what I did to set up the mount after adding it in the VirtualBox UI:

# Note the extra / at the beginning of the path because of msys/MinGW.
docker-machine.exe ssh default 'sudo mkdir --parents //e/Documents/workspace'
docker-machine.exe ssh default 'sudo mount -t vboxsf e/Documents/workspace //e/Documents/workspace'

It's convenient to do it that way because those commands will stay in your history even if you destroy the VM.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Nov 30, 2015

There is a way to do this without using VirtualBoxUI, just the code in shell?

ghost commented Nov 30, 2015

There is a way to do this without using VirtualBoxUI, just the code in shell?

@nathanleclaire

This comment has been minimized.

Show comment
Hide comment
@nathanleclaire

nathanleclaire Dec 2, 2015

Contributor

@ginolon Yes there is but you have to call out to the location of where VBoxManage is directly, as well as know the actual commands to create the shared folders.

Contributor

nathanleclaire commented Dec 2, 2015

@ginolon Yes there is but you have to call out to the location of where VBoxManage is directly, as well as know the actual commands to create the shared folders.

@jepma

This comment has been minimized.

Show comment
Hide comment
@jepma

jepma Dec 18, 2015

@ginolon you can do this like this VBoxManage sharedfolder add default --name "workspace" --hostpath /Volumes/Data/workspace/ where default is the name of your virtual-machine and /Volumes/Data/workspace the directory on your host machine.

jepma commented Dec 18, 2015

@ginolon you can do this like this VBoxManage sharedfolder add default --name "workspace" --hostpath /Volumes/Data/workspace/ where default is the name of your virtual-machine and /Volumes/Data/workspace the directory on your host machine.

@yelmu

This comment has been minimized.

Show comment
Hide comment
@yelmu

yelmu Jan 23, 2016

You don't need to run the additional step sudo mount -t vboxsf sharename /path if you use Users or /Users as a share/folder name in VirtualBox.

Check boot2docker readme, it tries to automatically mount some predefined VBox share names. /c/Users is automatically mapped to C:\Users but /Users can still be mapped to D:\Code in VBox GUI.

Run docker run -v /Users:/code and now /code in Docker container maps to D:\Code.

yelmu commented Jan 23, 2016

You don't need to run the additional step sudo mount -t vboxsf sharename /path if you use Users or /Users as a share/folder name in VirtualBox.

Check boot2docker readme, it tries to automatically mount some predefined VBox share names. /c/Users is automatically mapped to C:\Users but /Users can still be mapped to D:\Code in VBox GUI.

Run docker run -v /Users:/code and now /code in Docker container maps to D:\Code.

@alainkr

This comment has been minimized.

Show comment
Hide comment
@alainkr

alainkr Feb 19, 2016

Is it possible to script "sudo mount -t vboxsf ..." somewhere inside the boot2docker ? So that it is executed each time the docker-machine starts ?

@nathanleclaire Thanks

alainkr commented Feb 19, 2016

Is it possible to script "sudo mount -t vboxsf ..." somewhere inside the boot2docker ? So that it is executed each time the docker-machine starts ?

@nathanleclaire Thanks

@nikolakanacki

This comment has been minimized.

Show comment
Hide comment
@nikolakanacki

nikolakanacki Apr 14, 2016

Since this is one of the top search results, I'll just post what worked for me.

Host: Mac OSX 10.11
Docker: 1.10.3
VirtualBox: 5.0.16 r105871

  1. From VirtualBox UI (or cmd) share the folder you want available in the guest machine, have it automount. For this example, let's say the path is: /Volumes/DATA/dev and you named it: dev.
  2. Open your virtualbox console (from VBUI or ssh) and create /var/lib/boot2docker/bootlocal.sh file:
    $ touch /var/lib/boot2docker/bootlocal.sh
  3. Add the following content to it using vi (or whatever is available, nano isn't):
#!/bin/sh

# Make directory path to the folder you shared with VirtualBox.
# We'll make the exact structure you find on your host so it's easier
# to target with docker (1:1) from the host:
mkdir -p /Volumes/DATA/dev

# Mount it using "mount -t vboxsf <name> <path>":
mount -t vboxsf dev /Volumes/DATA/dev

(quick vi ref: open file > vi <filepath>, enter insert mode > i, save and quit > :wq)

And that's it!

We create /var/lib/boot2docker/bootlocal.sh because it is executed during boot (you can put loads of stuff in there to prepare your machine). Also, nothing outside /var/lib/boot2docker directory will be preserved once you stop the machine. Repeat for every directory you want shared.

Hope it helped.

nikolakanacki commented Apr 14, 2016

Since this is one of the top search results, I'll just post what worked for me.

Host: Mac OSX 10.11
Docker: 1.10.3
VirtualBox: 5.0.16 r105871

  1. From VirtualBox UI (or cmd) share the folder you want available in the guest machine, have it automount. For this example, let's say the path is: /Volumes/DATA/dev and you named it: dev.
  2. Open your virtualbox console (from VBUI or ssh) and create /var/lib/boot2docker/bootlocal.sh file:
    $ touch /var/lib/boot2docker/bootlocal.sh
  3. Add the following content to it using vi (or whatever is available, nano isn't):
#!/bin/sh

# Make directory path to the folder you shared with VirtualBox.
# We'll make the exact structure you find on your host so it's easier
# to target with docker (1:1) from the host:
mkdir -p /Volumes/DATA/dev

# Mount it using "mount -t vboxsf <name> <path>":
mount -t vboxsf dev /Volumes/DATA/dev

(quick vi ref: open file > vi <filepath>, enter insert mode > i, save and quit > :wq)

And that's it!

We create /var/lib/boot2docker/bootlocal.sh because it is executed during boot (you can put loads of stuff in there to prepare your machine). Also, nothing outside /var/lib/boot2docker directory will be preserved once you stop the machine. Repeat for every directory you want shared.

Hope it helped.

@janhartigan

This comment has been minimized.

Show comment
Hide comment
@janhartigan

janhartigan Aug 15, 2016

Anyone coming to this using Docker Toolbox on Windows can avoid running the mount lines manually by modifying C:\Program Files\Docker Toolbox\start.sh to include this:

STEP="Mounting web directory"
"${DOCKER_MACHINE}" ssh default 'sudo mkdir --parents //c/Web'
"${DOCKER_MACHINE}" ssh default 'sudo mount -t vboxsf c/Web //c/Web'

This can go after the step Checking status on $VM and before Setting env. Naturally, as mentioned above, the directory you've defined here has to be a shared folder in Virtual Box first (best to do this while the VM is off).

I prefer to use Docker for Windows (which is superior in just about every imagineable way), but sometimes I have to use Docker Toolbox because no Hyper V. I wish Microsoft would just make Hyper V a feature for all Win10 versions :-/

janhartigan commented Aug 15, 2016

Anyone coming to this using Docker Toolbox on Windows can avoid running the mount lines manually by modifying C:\Program Files\Docker Toolbox\start.sh to include this:

STEP="Mounting web directory"
"${DOCKER_MACHINE}" ssh default 'sudo mkdir --parents //c/Web'
"${DOCKER_MACHINE}" ssh default 'sudo mount -t vboxsf c/Web //c/Web'

This can go after the step Checking status on $VM and before Setting env. Naturally, as mentioned above, the directory you've defined here has to be a shared folder in Virtual Box first (best to do this while the VM is off).

I prefer to use Docker for Windows (which is superior in just about every imagineable way), but sometimes I have to use Docker Toolbox because no Hyper V. I wish Microsoft would just make Hyper V a feature for all Win10 versions :-/

@cpprookie

This comment has been minimized.

Show comment
Hide comment
@cpprookie

cpprookie May 5, 2017

@juharris thanks a lot, It works as it should be

@juharris thanks a lot, It works as it should be

@abarcenas29

This comment has been minimized.

Show comment
Hide comment
@abarcenas29

abarcenas29 Aug 11, 2017

@juharris I get an error when I tried your fix.

Looks like something went wrong in step ´Mounting web directory´... Press any key to continue...

My change

STEP="Mounting web directory"
"${DOCKER_MACHINE}" ssh default 'sudo mkdir --parents //c/www/docker'
"${DOCKER_MACHINE}" ssh default 'sudo mount -t vboxsf c/www/docker //c/www/docker'

My docker projects are located in C:\www\docker

abarcenas29 commented Aug 11, 2017

@juharris I get an error when I tried your fix.

Looks like something went wrong in step ´Mounting web directory´... Press any key to continue...

My change

STEP="Mounting web directory"
"${DOCKER_MACHINE}" ssh default 'sudo mkdir --parents //c/www/docker'
"${DOCKER_MACHINE}" ssh default 'sudo mount -t vboxsf c/www/docker //c/www/docker'

My docker projects are located in C:\www\docker

@juharris

This comment has been minimized.

Show comment
Hide comment
@juharris

juharris Aug 11, 2017

@abarcenas29 wow people are still using Docker Toolbox? If you have Windows 10, then there's better more native like support now: https://store.docker.com/editions/community/docker-ce-desktop-windows

As for your error, I'm really not sure sorry and I haven't used Docker Toolbox in months. Maybe your C drive is already mounted? Which line gave the error?

juharris commented Aug 11, 2017

@abarcenas29 wow people are still using Docker Toolbox? If you have Windows 10, then there's better more native like support now: https://store.docker.com/editions/community/docker-ce-desktop-windows

As for your error, I'm really not sure sorry and I haven't used Docker Toolbox in months. Maybe your C drive is already mounted? Which line gave the error?

@janhartigan

This comment has been minimized.

Show comment
Hide comment
@janhartigan

janhartigan Aug 11, 2017

@juharris the underlying problem is that most people don't want to (or have the means to) upgrade to Windows 10 Pro. You can't use Docker for Windows with the standard edition of Windows 10. I personally have Pro on all of my machines, but I feel like Microsoft should make Hyper-V a base feature so they don't lose a bunch of devs to other operating systems. Docker for Windows is a million times more usable than Docker Toolbox, and that alone makes the extra $100 worth it for me, but not everyone is going to have the same economics.

@juharris the underlying problem is that most people don't want to (or have the means to) upgrade to Windows 10 Pro. You can't use Docker for Windows with the standard edition of Windows 10. I personally have Pro on all of my machines, but I feel like Microsoft should make Hyper-V a base feature so they don't lose a bunch of devs to other operating systems. Docker for Windows is a million times more usable than Docker Toolbox, and that alone makes the extra $100 worth it for me, but not everyone is going to have the same economics.

@jeremyVignelles

This comment has been minimized.

Show comment
Hide comment
@jeremyVignelles

jeremyVignelles Nov 20, 2017

@juharris Yeah, people are still using Docker Toolbox, and I'm one of those: Hyper-V is for me a huge source of frustration, it doesn't allow me to use Virtualbox at the same time because it takes ownership of the virtualization chip. All my virtual machines are on Virtualbox, which I find way more convenient to use for linux VMs, so I don't want to switch. Switching between Hyper-V and Virtual box requires rebooting and reinstalling Hyper-V each time, so, sadly, I won't upgrade to the new Docker

@juharris Yeah, people are still using Docker Toolbox, and I'm one of those: Hyper-V is for me a huge source of frustration, it doesn't allow me to use Virtualbox at the same time because it takes ownership of the virtualization chip. All my virtual machines are on Virtualbox, which I find way more convenient to use for linux VMs, so I don't want to switch. Switching between Hyper-V and Virtual box requires rebooting and reinstalling Hyper-V each time, so, sadly, I won't upgrade to the new Docker

@jeremyVignelles

This comment has been minimized.

Show comment
Hide comment
@jeremyVignelles

jeremyVignelles Nov 20, 2017

I just found another option to share a folder to the virtualbox VM: You can create your VM with the following command line:

docker-machine create --driver virtualbox --virtualbox-share-folder "c:\project:/c/project" default

For that to work, you will need to remove and recreate your VM, you will need to add the same option if you want to keep the /c/Users share, but you need to enter it once and it's kept 😉

source : #3908

jeremyVignelles commented Nov 20, 2017

I just found another option to share a folder to the virtualbox VM: You can create your VM with the following command line:

docker-machine create --driver virtualbox --virtualbox-share-folder "c:\project:/c/project" default

For that to work, you will need to remove and recreate your VM, you will need to add the same option if you want to keep the /c/Users share, but you need to enter it once and it's kept 😉

source : #3908

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment