Here is an example docker-compose that will setup Postgres, pgadmin and Traefik. The Postgres container listens by the default on port 5432, I'm also setting up a TCP entrypoint and router in Traefik on the same port.
Traefik Dashboard would be accessible at traefik.docker.localhost, given you have that alias configured in Docker.
pgadmin is at pgadmin.docker.localhost and from its own Dashboard you can setup a connection to Postgres directly, by using the address postgres or through Traefik, by using traefik as the server address this time. It works because the rule on the tcp entrypoint is set to *, so its basically redirecting everything Traefik receives on port 5432 to Postgres at port 5432.
I hope that gives you a good idea on how things can be stitched together as we have both HTTP and TCP routers configured on this example.
Alternatively if your Postgres server is an external server you might want to set it up with a static routing rule via the File provider instead of relying on Docker labels in this case. For that I left some lines commented out on the previous static + docker compose files. Here is an example for its content:
The issue when not running on the same compose is probably because either the network is not reachable or the address is not resolvable. When you apply a dynamic configuration with the File provider you assume Traefik can reach directly to the addresses specified under servers:, in my example you would assume postgres resolved to a network address in the same network as Traefik.
As for Apache Tomcat and HTTP I don't have any ready examples at hand but the structure should be pretty much the same as for postgres, except maybe you want HTTP routers instead of TCP.
If anyone else have examples on this please follow up as it would be really helpful here and also on this other post