Backend to Backend communication failing

Hello, I have two service API and DBManager, I've added

API service
api_1
"labels": [
        "traefik.enable=true",
        "traefik.http.routers.api.rule=Host(`app.localhost`) && PathPrefix(`/api`)",
        "traefik.http.routers.api.entrypoints=web-secure",
        "traefik.http.routers.api.tls=true",
        "traefik.http.services.api.loadbalancer.server.port=5002"
      ],
      "networks": [
        "network"
      ],
      "ports": [
        "5002:5002"
      ],

This is my DB

DBManager service
dbmanager_1
"labels": [
        "traefik.enable=true",
        "traefik.http.routers.dbmanager.rule=Host(`app.localhost`) && PathPrefix(`/dbmanager/`)",
        "traefik.http.routers.dbmanager.entrypoints=web-secure",
        "traefik.http.routers.dbmanager.tls=true",
        "traefik.http.services.dbmanager.loadbalancer.server.port=5005"
      ],
      "networks": [
        "network"
      ],
      "ports": [
        "5005:5005"
      ],

My proxy container

"proxy": {
      "command": [
        "--api",
        "--api.debug",
        "--api.insecure=true",
        "--log.level=DEBUG",
        "--providers.docker=true",
        "--providers.docker.exposedbydefault=false",
        "--entrypoints.web-insecure.address=:80",
        "--entrypoints.web-secure.address=:443",
        "--entrypoints.web-secure.forwardedheaders.insecure"
      ],
      "image": "traefik:v2.9.8",
      "networks": ["network"],
      "ports": [
        "80:80",
        "443:443",
        "8080:8080"
      ],

Issue is, accessing app.localhost/api works locally, so does app.localhost/dbmanager but communication between these 2 when using the traefik host (app.localhost) does not work. It gives me error 500

Where is all the JSON coming from? Usually it’s traefik.yml and docker-compose.yml.

Where is your TLS defined?

Why do your services open ports? Why is one ports changing port number? It shouldn’t even run as both services expose 5002.

It is from docker-compose.json file.

TLS is not defined, just set to true.

And yes, I just changed DBManager port to 5005 but still won't communicate in docker.

If you set TLS to true without cert files or LetsEncrypt, Traefik will generate a custom cert file, browsers will not trust it, you will see an error message. Not sure if Traefik will trust another Traefik with the same certs, you potentially need --serverstransport.insecureskipverify=true in proxy command.

Ports is not needed for your services, they shouldn't be exposed. Traefik will connect to their internal port within the container, the one you define with loadbalancer.server.port.

Note that PathPrefix just checks for the path, your service needs to be available at that path (/api and /dbmanager) when directly accessed via http.

Try to enable the Traefik dashboard and check the routers and services.

What exactly do you try to access, what's the error in log files?