Container can't connect to another container on same host using external DNS or host IP

It seems to be very similar to another topic we are currently discussing

Edited:

On the other hand your situation could have been solved by network aliases. Example:

services:
  test:
    depends_on:
      - httpd
    image: nicolaka/netshoot
    command:
      - nslookup
      - yourdomain.com

  httpd:
    image: httpd:2.4
    networks:
      default:
        aliases:
          - yourdomain.com

Run the test:

docker compose up

And the domain will be resolved to the ip address of the container.