How do I setup a network between 2 centos VM's using Vagrant/Virtualbox and a docker container using docker for mac. They all need to be able to access each other.
Currently I'm not able to access the vm's from within a docker container.
Vagrant setup:
Vagrant.configure("2") do |config|
config.vm.define "build" do |build|
build.vm.box = "centos/7"
build.vm.provider "virtualbox"
build.vm.hostname = "server-a"
build.vm.network "private_network", ip: "192.168.50.4"
end
config.vm.define "test" do |test|
test.vm.box = "centos/7"
test.vm.provider "virtualbox"
test.vm.hostname = "server"
test.vm.network "private_network", ip: "192.168.50.5"
end
end
The vm's can access each other but the docker container can't access the vm's
docker network create -d bridge --gateway=192.168.50.1 --subnet=192.168.50.1/24 mybridge
docker run --network=mybridge alpine ping 192.168.50.4
=> not able to connect
You need to connect network where you run a docker container and a network where you boot vagrant VMs to the same bridge device on your host machine:
1. Create docker network:
Docker creates bridge with name
br-<network_id>
on host machine:2. Connect vagrant VMs network to the same bridge device:
3. Boot VMs:
4. Start docker container in
mybridge
network: