Connection refused docker container to external api and another container

I am trying to implement keycloak oauth2 for my spring-boot microservices application. I am using a docker-compose file to run my application on docker. I am new to docker and I don’t know about networking in docker.

case 1- =
when I use this above url, I get connection refused error on my gateway. Since my application and keyloak were on the same server and I cannot connect two containers using domain name, I tried configuring keycloak on another server but I still get the same error.

case 2- = https://keycloak:8443/realms/back-office-realm
when I use the container name, I get - No subject alternative DNS name matching keycloak found.
If I try to use http and port 8080, I get - java.lang.IllegalStateException: The Issuer provided in the configuration did not match the requested issuer

I hope someone can guide me what I am doing wrong or what should be the futher steps.