Docker Network Wildcard Subdomain routing of internal requests to nginx service

Solution for Docker Network Wildcard Subdomain routing of internal requests to nginx service
is Given Below:

I’m building an e2e test suite inside a docker container for CI.
It has 3 services (admin, platform, dashboard) which all connect to a postgres instance.
I use nginx as a reverse proxy to direct the traffic to the correct service based on the subdomain.
Dashboard (dashboard.localtest.me) and Admin (admin.localtest.me) each have their own subdomain and everything else goes to Platform (ex. accounts.localtest.me, public.localtest.me) and there are hundreds of subdomains. The services are on their own ports as well as part of how the product is designed.

Currently I can bring all this up in docker-compose, make requests to <foo>.localtest.me:8080 from my browser and nginx will direct all the traffic to the correct endpoints. Works great.

But when the Cypress service tests start making requests (from inside the docker host) they don’t resolve. My assumption is that since the hostname isn’t resolving then the request isn’t going to the nginx service, which means it can’t get routed to the correct product service (admin, platform, or dashboard)

If I can route everything to nginx with a dns wildcard (*.localest.me) I think that would work but I can’t figure out what modules or tools can allow for that. Everything I’ve found is for handing a reverse proxy connecting to the docker host, not containers making url requests internally.

TL;DR
How can I allow cypress container to make wildcard GET requests (*.localtest.me) to my nginx reverse_proxy container

This is roughly what my docker compose looks like, I’ve removed any of the internal env vars that aren’t relevant

    services:
      postgres:
        build:
          context: ./
          dockerfile: postgres.dockerfile
      ports:
        - 5432:5432
        
      dashboard:
        build:
          context: ./
          dockerfile: web.dockerfile
        ports:
          - 9001:9000
      
      platform:
        build:
          context: ./
          dockerfile: web.dockerfile
        ports:
          - 8001:8000
      
      admin:
        build:
          context: ./
          dockerfile: web.dockerfile
        ports:
          - 7001:7000
      
      nginx:
        restart: always
        image: nginx
        build:
          context: ./
          dockerfile: nginx.dockerfile
        ports:
          - 8080:80
          - 443:443
          - 8000:8000
          - 9000:9000
          - 7000:7000
      
      cypress:
        image: cypress-testing
        build:
          context: ./
          dockerfile: cypress-tests.dockerfile
        ports:
          - 6000:6000

Here is my nginx.conf

server {
    listen 80;
    listen 9000;
    server_name dashboard.localtest.me;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;

        proxy_pass http://dashboard:9000/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;

        chunked_transfer_encoding off;
    }
}

server {
    listen 80;
    listen 7000;
    server_name admin.localtest.me;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Connection "";

        proxy_pass http://admin:7000/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;

        chunked_transfer_encoding off;
    }
}

server {
    listen 80;
    listen 8000;
    server_name ~(^|.)localtest.me$;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;

        proxy_pass http://platform:8000/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;

        chunked_transfer_encoding off;
    }
}