Exposing ports half-works

I created a Vagrantfile for a VM, the provider is VirtualBox. The Vagrantfile exposes some ports in this way:

if (MINDSDB_APIS.include? 'mysql') and PORT_MYSQL.to_i > 0
    config.vm.network 'forwarded_port', guest: 47335, host: PORT_MYSQL
if (MINDSDB_APIS.include? 'http') and PORT_HTTP.to_i > 0
    config.vm.network 'forwarded_port', guest: 47334, host: PORT_HTTP

(those ports are not standard but they’re correct, the reason would be a bit long to explain here)

Inside the VM, everything seems to work correctly: I can connect to 47335 with a MySQL client and get results from 47334 with curl.

Outside of the VM, the MySQL client and curl don’t seem to connect:

# mycli -hlocalhost -p3306
(2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")

# curl -g
curl: (7) Failed to connect to port 47334: Connection refused

Before you think that things vaguely make sense, I want to let you know that netcat communicates as expected. If I shutdown the servers in the VM and start nc -l 47334 (or 47335), I’m able to run nc -v 47334 (or 47335) in the host system, and see the output appearing in the VM’s shell as expected.

I tried running Apache and another version of MySQL in the VM, nothing changes. At this point, I don’t even know if the problem lies in my Vagrantfile, in Vagrant, or in VirtualBox. Anyone can help?

Complete noob here (I came to the forum to try and figure out if there is a better way to map ports from guest → host using virtualbox)

While looking for those solutions I stumbled over and bookmarked this page, I am wondering if it might explain & correct your error:

Vagrant’s port forwarding not working

Yes, it is old, but it sounds like the same issue possibly.