How to Forward a Subdomain to an External Nginx on localhost:8080 Using Traefik?

I'm using Traefik v3 in a Docker Swarm environment and I need to forward a subdomain (e.g., api.mydomain.com) to an external Nginx server running on localhost:8080.

Since this Nginx instance is running directly on the host machine, and not inside a container, I need to ensure Traefik can properly route traffic to it.

i've try something like this:

  proxy-to-host:
    image: alpine
    command: tail -f /dev/null
    deploy:
      replicas: 1
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.proxy-to-host.rule=Host(`api.mydomain.com`)"
        - "traefik.http.routers.proxy-to-host.entrypoints=web"
        - "traefik.http.services.proxy-to-host.loadbalancer.server.url=http://host.docker.internal:8080"

This is not possible. Accessing localhost inside a container is not localhost of the host.

And host.docker.internal is a special function of Docker Desktop development tool.

If you want to connect to another service outside containers on the host, you need to use the individual IP of the host, not 127.0.0.1.

1 Like

@bluepuma77 Thanks for your help and for responding

Even though I'm trying to use the host's local IP, it's not working. I've already confirmed that the container has access to the host's IP.

How can I configure Traefik to access a local host IP and port?