Keycloak and Grafana docker-compose

Dear all,
I’m configuring an application using a docker-compose where there are grafana and also keycloak as identity provider.
When I go to community.grafana.com grafana redirect me to the keycloak login page, but once I authenticate keycloak redirect me to grafana which shows an error message like:

login.OAuthLogin(NewTransportWithCode)

The grafana log file says:

t=2020-07-22T13:54:16+0000 lvl=eror msg=login.OAuthLogin(NewTransportWithCode) logger=context userId=0 orgId=0 uname= error=“Post "https://localhost:10443/auth/realms/simile/protocol/openid-connect/token\”: dial tcp 127.0.0.1:10443: connect: connection refused"
t=2020-07-22T13:54:16+0000 lvl=eror msg=“Request Completed” logger=context userId=0 orgId=0 uname= method=GET path=/login/generic_oauth status=500 remote_addr=172.24.0.1 time_ms=1 size=1744 referer=

Hereinafter my env configuration:

GF_AUTH_GENERIC_OAUTH_NAME=OAuth
GF_AUTH_GENERIC_OAUTH_ENABLED=true
GF_AUTH_GENERIC_OAUTH_ALLOW_SIGN_UP=true
GF_AUTH_GENERIC_OAUTH_CLIENT_ID=simile-grafana
GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET=66eb44de-5d54-4fe8-ac49-9cc6832cb4e1
GF_AUTH_GENERIC_OAUTH_SCOPES=openid profile
GF_AUTH_GENERIC_OAUTH_EMAIL_ATTRIBUTE_NAME=email
GF_AUTH_GENERIC_OAUTH_AUTH_URL=https://localhost:10443/auth/realms/simile/protocol/openid-connect/auth
GF_AUTH_GENERIC_OAUTH_TOKEN_URL=https://localhost:10443/auth/realms/simile/protocol/openid-connect/token
GF_AUTH_GENERIC_OAUTH_API_URL=https://localhost:10443/auth/realms/simile/protocol/openid-connect/userinfo
GF_AUTH_GENERIC_OAUTH_TLS_SKIP_VERIFY_INSECURE=true

Why is this happening?
Thank you for your help
Daniele

If Grafana and Keycloak are running in different containers, you should set localhost to whatever the name of the Keycloak container is. Port forwarding doesn’t work within the Docker network.

Thank you for the tip.