How to network a VirtualBox virtual machine with a docker container?

In order to join the docker container to the same network as the VirtualBox virtual machine, the virtual machine of the docker container needs to be created on the same network.

The VirtualBox Host-Only Network runs on the 192.168.56.1/24 network.  When creating the default Docker virtual machine ensure that the VirtualBox Host Only CIDR is 192.168.56.1/24 then all containers that run on this Docker machine will run on the same network. If you already have default Docker Machine then you will have to delete it (see below).  The default Docker virtual machine can be created using the following command.

docker-machine create --driver "virtualbox" --virtualbox-cpu-count "4" --virtualbox-disk-size "30000" --virtualbox-host-dns-resolver --virtualbox-hostonly-cidr 192.168.56.1/24 --virtualbox-hostonly-nictype "82540EM" --virtualbox-memory "4096" default

Once the default Docker machine has been created you can check the ip address with the following command

docker-machine ip

This default virtual machine is now on the VirtualBox Host-Only Network and any containers on the default virtual machine will be able to communicate with other VirtualBox virtual machines using the Host-Only Adapter & the correct network configuration.


The above creates the default Docker machine.  You may need to delete the default machine before using the above command to create one.  You can delete a default machine with the following command.

 docker-machine rm -f -y default

If you get “Error removing host “default”: open C:\Users\Bish\.docker\machine\machines\default\config.json: The system cannot find the file specified.” error then run the following commands:

cd %userprofile%/.docker/machine/machines/default

NUL > config.json

Ignore the access is denied message and reboot.  After rebooting retry the remove command.

 docker-machine rm -f -y default