Connecting from Container to host

One problem I faced was to connect to the host from a container. (It was because of a live logging application)

I achieved the desired result by doing adding the extra_hosts section in my compose file:

services:
	example:
	...
		extra_hosts:
		  - logserver.local: host-gateway

With this I can call logserver.local inside of my container and it gets routed to the localhost.

If you want to configure it so that host-gateway points to a specific IP address you can configure it in the /etc/docker/daemon.json

{ "host-gateway-ip": "<desiredIP>" }

This can be especially useful if you install docker without docker-desktop on WSL. Then you can route your host-gateway to the virtual network-interface connecting to windows.