DEV Community

Discussion on: How To: Ssh Into Ubuntu VM Virtualbox From Host Machine

Collapse
 
bharatv profile image
Bharat

How can I use internal docker containers via IPs like 172.17.0.2 of it in the guest machine
Example - I am making an application which requires mysql/mongodb which I've installed as a container of guest machine which is Ubuntu 20.04
I want to add server properties in the app running on windows ... what ip can be used?

Collapse
 
selllami profile image
Yassine Sellami • Edited

You can't add PF for docker container IPs, Because each time u get a new IP for ur container.
--> 1 windows hosting VBox.
--> 2 Ubuntu 20.04 in VBox.
--> 3 Mysql in docker (port 3306).

# ex: inside (2) make sure mysql run on 5200
$ docker run --name some-mysql -p 5200:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7.40
# MySql now is reachable from (2) localhost:5200
# Check ur Firewall inside (2)
$ ufw allow 5200
$ ufw status
-- 
# Get ur VMs name
$ VBoxManage list vms 

# Add new port forwarding, with empty guest ip
$ VBoxManage modifyvm "MyVmName" --natpf1 "tcp-pf5200,tcp,,5200,,5200"
Enter fullscreen mode Exit fullscreen mode