Search code examples
docker-composecontainersvirtual-machinevirtualboxvirtualization

VirtualBox - connection between VMs, host and Internet, and access to containerized services running inside a VM


I have three VirtualBox VMs running different systems. I need all the VMs communicating between them and with Internet access.

Now, I have two network adapters configured for each VM. The first network adapter is configured with NAT and DHCP, for Internet access. The second network adapter is configured as "host-only", with a static IP. The communication among the VMs is ok, but I need to access some containerized services running inside one of the VMs. These services are running through docker-compose.

As I cannot configure port forwarding for a "host-only" adapter, I am searching for the best way to deal with this problem. Most of the results I find on the Internet suggest what I already did: NAT + host-only. So, what is the best configuration for VBox VMs running with static IPs, communicating to each other and to Internet, and allowing access to containerized services that run on them?


Solution

  • After one day searching for a solution, thinking the problem could be with the VBox network configuration, I discovered that the docker-compose file was restricting the access only to the localhost:

    ports
    - 127.0.0.1:8500:8500
    

    To solve my problem, I just changed all this information to:

    ports
    - 8500:8500
    

    Now, I am successfully accessing the services running in containers inside the VBox VM. I tried to access using my first configuration, which is NAT for the first adapter and host-only with a static IP for the second adapter, and using the bridged configuration. I got success with both.