Keyclock outside from Docker (another service on local machine) - Seems I cannot connect from outside

Hello,

I´m sorry, I´m a beginner.
I have two question

I defined my Dockerfile like:

FROM quay.io/wildfly/wildfly:26.1.3.Final-jdk11

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

COPY my-standalone.xml /opt/jboss/wildfly/standalone/configuration/
COPY myapp.war /opt/jboss/wildfly/standalone/deployments/
COPY module.xml /opt/jboss/wildfly/modules/system/layers/base/com/mysql/main/
COPY mysql-connector-java-8.0.12.jar /opt/jboss/wildfly/modules/system/layers/base/com/mysql/main/

EXPOSE 8080 9990

# Run with custom configuration
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c","my-standalone.xml"]

If I start docker my wildfly application and server it´s running.
But I have also a dependency to a Keyclock application, which runs on my local machine (another process, not from docker…).
It seems Docker is not able to use this from my application.
The URL from Keyclock is: http://0.0.0.0:9009/auth

What do I need to change?

And my second question is, if I use on top a docker-compose.yaml file, which is also using the Dockerfile. Do I need to change something also there to get Keyclock running / considering?

Thanks for your help

0.0.0.0 is not an ip address as such, but it indicates to “listen on all available IP addresses” to an application.

To connect to a service listening on 0.0.0.0, you need to use a real IP address. The host usually has localhost/127.0.0.1 and a custom one like 12.34.56.78. As localhost within a container is really only localhost within container, not on host, you must use the other IP to connect.

Thank you - you are right: http://localhost:9009/auth is also working.
But I still don´t understand where I have to define this URL in the Dockerfile or docker-compose.yaml file ?

In my app I defined the URL only here:

oidcConfig.discoveryURI = http://localhost:9009/auth/realms/myapp/.well-known/openid-configuration
oidcConfig.clientId = myapp

But it seems Docker cannot access http://localhost:9009

Let me rephrase my post:

Within a container you can not use localhost to connect to a service listening on hosts localhost.

… unless the container uses the host network. Since we never saw the compose file, it could be why @vished2000 repots that localhost is working for him.

The only reason why I would use the host network, is when I have a container that needs to act on udp broadcast traffic. For everything else I would not want to lose the network namespace isolation provided by bridge networks.

1 Like