How to get Docker Desktop to bind on a virtual interface

Viewed 53

If I run Docker locally and I bind the containers' ports, I usually connect with them through localhost and not through the dynamically created IP address. I might start a MySQL container, bound with 3306:3306 and can then connect with it to localhost:3306.

If I am using a virtual machine in Windows to run Docker in (e.g. with VirtualBox), the VM has its own interface (e.g. VirtualBox Host-Only Network) which might have an IP address of 192.168.50.1. I can now connect to a MySQL container via 192.168.50.1:3306.

Using a different interface/network for my containers is useful during development because I free up my localhost ports for other things and many browsers treat localhost differently than it does other addresses.

However, Docker Desktop also has advantages over a VM:

  • Not having to manage the VM
  • Testcontainers out-of-the-box
  • Docker Desktop is nice

Should it not be possible to get Docker to bind to ports on a virtual interface instead of localhost, e.g. by creating a Windows virtual switch or even by using the existing VirtualBox network? And is it possible to do this for Docker Desktop (on Windows) for all containers by default?

This answer indicates there's an --ip option available when starting the Docker daemon, but:

  • Which IP address do I use here? The gateway is the only IP address that I have configured for a virtual switch.
  • What is the equivalent for Docker Desktop?
0 Answers
Related