Is it better to share the same network for Trafic container and exposed containers in Docker?

Traefik with providers.docker or providers.swarm will use Docker service/container IPs from Docker networks to connect to the target service. So Traefik and target service need to be connected to the same Docker network, implicit or explicit.

Yes, I also found this in the official documentation. But it could work if Traefik and exposed containers are not connected to the same network. I don't know why. Here's my test files (Changed from the official example):

.
├── traefik
│   └── docker-compose.yaml
└── whoami
    └── docker-compose.yaml

traefik/docker-compose.yaml:

services:

  traefik:
    image: "traefik:v3.3"
    container_name: "traefik"
    command:
      #- "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

whoami/docker-compose.yaml:

services:

  whoami:
    image: "traefik/whoami"
    container_name: "simple-service"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
      - "traefik.http.routers.whoami.entrypoints=web"

/etc/hosts:

127.0.0.1 whoami.localhost

After starting both compose, I can access whoami.localhost and see the page.

docker network ls:

NAME              DRIVER    SCOPE
traefik_default   bridge    local
whoami_default    bridge    local

ENV: Use OrbStack on macOS