Or as @meyay pointed out, install Docker Desktop on Linux
It works by default on macOS and Windows because you can run Linux containers on those operating systems only in a Linux virtual machine manually or using Docker Desktop, which runs a VM while you can still run the client on the host operating system. It should work the same way on Linux too when using Docker Desktop.
If you just use --add-host
with the host-gateway
alias, it will just point to the host gateway while Docker Desktop’s host.docker.internal
domain points to the “localhost” of your host machine so you don’t have to publish the ports on the LAN IP or any Docker network gateway IP.
If you want to access the local port without Docker Desktop, you can do it as I described here