Since the targets are not running inside the prometheus container, they cannot be accessed through localhost. You need to access them through the host private IP or by replacing localhost with docker.for.mac.localhost or host.docker.internal.
On Windows:
host.docker.internal(tested on win10, win11)
On Max
docker.for.mac.localhost