Run Virtualbox inside docker container, on Windows host - windows

I know this is not what docker containers should be used for, but hear me out. I'm trying to port over a local environment that is currently run on Windows 10 with Chef, Vagrant & Virtualbox.
I believe it is possible to do this in Ubuntu by installing Virtualbox on the host, then mounting the /dev/vboxdrv directory into the container. While there is a vboxdrv directory for the Windows installation C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv, it won't work for a Linux-based container.
Is it possible to get Virtualbox running inside of a Docker container while on a Windows host? I doubt it, but thought I'd ask to confirm in case I had missed some nice workaround.

Related

Connecting Docker Windows WSL Ubuntu to VMware Ubuntu

I am trying to connect my Windows 10 Home system to be able to run full Linux OS Docker containers. I have installed Docker on both WSL Ubuntu 18.04 as well as a VMware Ubuntu 18.04.
I was trying to follow this guide.
However, I get stuck trying to configure the Daemon as per the instructions.
Can’t use Docker for Windows?
This is only necessary if you are NOT running Docker for Windows!
No problem, just configure your Docker daemon to use -H tcp://0.0.0.0:2375 and --tlsverify=false. Then you can follow along with the rest of this guide exactly.
If you go down this route, I highly recommend rolling your own VM with VMware Player instead of using the Docker Toolbox because VirtualBox has crazy edge case shared folder bugs that will ruin your life at some point. Don’t worry, VMware Player is free. Just Google how to set up Ubuntu 16 server on VMware Player.
When I try to change the Docker Daemon by making a daemon.json file I get errors. I've also tried editing the .profile files and the .bashrc as per other guides (another guide), with no luck.
I am unable to check the DOCKER_HOST variable on the VM Ubuntu.
Don't make things complicated. In your case, why WSL if you just want to connect to a remote daemon? Why not simply use the windows docker client?
Setup you favorite local VM with docker.
Example: I have installed a CentOS distro running on local VMWare Workstation. All Hyper-V of course deinstalled/deactivated.
In this VM, enable tcp access for the daemon.
If you have a systemd linux distro (like mine CentOS), execute this:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo echo '[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375' >> /etc/systemd/system/docker.service.d/options.conf
sudo systemctl daemon-reload
sudo systemctl restart docker`
Test if the port is open with docker info. You should get an API access warning at the bottom result.
Download the Windows docker cli zip from here: https://download.docker.com/win/static/stable/x86_64/
Move the docker.exe to any folder, for ex. your Documents folder.
Then put this folder path into your Windows PATH variable.
Set the docker host: Open PowerShell, execute setx DOCKER_HOST <VM-IP>:2375 and close it.
Open a new PowerShell and call docker info.
You should see the docker and daemon infos.
Do what ever you like now... :-)

Running virtualbox/vagrant in a cloud instance

I've tried two things:
First, I tried to install virtualbox on a EC2 machine, which proved to be impossible.
Second, I was able to install both vagrant and virtualbox on a Digital Ocean droplet, but when I tried to run vagrant up, it got stuck on Booting VM.
Several sources on Internet say that it is not possible to run a VM inside a virtualized environment (both Amazon and Digital Ocean provide this).
Is there any way I can solve this with another provider, or is there a way to run vagrant/virtualbox in Amazon or Digital Ocean?
Install VirtualBox and Vagrant on a physical machine such as your desktop
Run the 3 commands from the command line:
vagrant init somenameyoumakeup file://urlToYour.box
vagrant up
vagrant halt
Open the VirtualBox UI
Export the Virtual machine to OVA format using the File -> Export menu
Follow the guide here for importing an OVA: https://aws.amazon.com/ec2/vm-import/

Volume sharing in Docker and Virtualbox

I have installed docker toolbox on my Windows PC,when i install containers on it using Kitematic, I want to share a folder with my local machine. However docker runs in virtualbox on the default machine in VirtualBox.
So, i guess i first have to do a fvolume share of the virtualbox vm with my local machine and then a second share of the docker container with the folder that I shared in virtualbox. Could someone assist me in this please?
No, you shouldn't need to share any more folder: docker-machine will create a VM which auto-mount C:\Users\<yourLogin>.
docker-machine ls
docker-machine ssh default
cd /C/Users/<yourLogin>
You can mount other folders from your hosts, but you don't have to.
I'm running docker version 18.03.0 ce on Windows 10, and the C:\Users folder is shared as /c-users on the docker VM (default), so using the command line
docker run -it -v /c-users/my_windows_user/project:/media/project ubuntu:16.04 bash
I can access the Windows project files from /media/project within the Ubuntu container

How do share the same VM between Windows and Linux when using Vagrant?

I have two hosts, one Windows and one Linux, both with Vagrant and VMware Workstation installed and everything works perfectly fine in their own environment. However, when I create an guest VM in Linux and I do vagrant up in Windows, then Vagrant will delete(!) everything in the .vagrant directory and attempt to fetch the base image. The same thing happens if I do a vagrant init and vagrant up in Windows and then a vagrant up in Linux. How do I prevent this from happening? Is there anyway to share the same VMs between Windows and Linux using Vagrant?
I'm running Windows 7, Ubuntu 14.04, Vagrant 1.6.5, VMware Workstation 10.0.3. This problem occurs for all guest operating systems.
The content of the .vagrant directory can be OS specific, and the internal state of VMware for sure.
I don't think there is easy way to share the same VM instance between the two hosts. The Vagrant way is to provision the VM so you only share the base box and then each user/OS spins up their own instance.
Another option would be to use vagrant package and vagrant box add to transfer the configured box, but that doesn't work with the VMware provider.
Yet another approach would be to use a cloud provider like AWS or Digital Ocean and just ssh into the box. Or maybe even use the vagrant-managed-servers plugin. Your question didn't hint what you use the Vagrant VM for, so it's difficult to tell what would be the best solution.
The following has been tested using the VirtualBox Vagrant provider with Windows 10 and Ubuntu 18.04 in a dual boot setup with a shared NTFS drive where D:\ in Windows is accesible as /mnt/d/ in Linux.
First (but not indispensable if I'm not wrong), set the VAGRANT_HOME environment variable in both Windows and Linux to the same place, e.g.:
Windows, D:\.vagrant.d
Linux, /mnt/d/.vagrant.d
Then create a new machine from one of the OSes, from Linux in the following example:
$ cd /mnt/d/vagrant_machines/machine1
$ vagrant init
$ vagrant up
Then boot in Windows and first backup D:\vagrant_machines\machine1\.vagrant just in case case its contents get accidentally deleted.
Then register from VirtualBox the existing VM, e.g. D:\virtualbox_machines\machine1_default_1587262647987_91775\machine1_default_1587262647987_91775.vbox.
Then run the following:
>vagrant.exe status
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.
The UID used to create the VM was: 1000
Your UID is: 0
And update D:\vagrant_machines\machine1\.vagrant\machines\default\virtualbox\creator_uid to your current UID (0 in this example).
Then start the machine:
>vagrant status
>vagrant up
Finally, note that you will require to update the creator_uid each time that you switch OSes, which you might want to automate.

Windows 8 HOST Vagrant spinup GUEST Ubuntu dev followed with Ansible manage dev stack from GUEST

I am working with Vagrant to provision Ubuntu servers using bash. I would like to cut my teeth on Ansible however I understand that Ansible does not currently run on Windows Host.
Is something like the following a reasonable work-around?
On Windows Host, use Vagrant to spin-up a basic Ubuntu Dev Box, including Ansible tools. From the Guest Dev Box use Ansible to run local tasks to further build it out. From the Dev Box I would use Ansible to spin-up/manage other Digital Ocean droplets from this Dev Box.
Your easiest workaround is probably to use virtualbox to start a linux/ubuntu virtual running on your Windows box, then to run Vagrant inside of that virtual. Yes, it's turtles all the way down- windows running virtualbox+ubuntu running virtualbox+ubuntu+vagrant.
Of course, the first layer won't be managed by Vagrant or Ansible, though you could do most of the configuration management after bootstrapping it.
Another option is to have a small dev box in your virtual hosting provider (Digital Ocean) where you manually install and launch vagrant/ansible from.
Alternately, dual boot or switch to a Linux or OSX machine :)

Resources