I have two docker containers, one running Keycloak 4.7.0.Final, and one running Postgresql.
Keycloak Dockerfile
FROM jboss/keycloak:4.7.0.Final
ADD themes/mytheme /opt/jboss/keycloak/themes/healthjoiner
ADD modules /opt/jboss/keycloak/modules/system/layers/keycloak
ADD standalone-ha.xml /opt/jboss/keycloak/standalone/configuration/
ADD keycloak-config.json /opt/jboss/
RUN mkdir -p $JBOSS_HOME/standalone/data
CMD ["-b", "0.0.0.0", "-Dkeycloak.migration.action=import -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/opt/jboss/keycloak-config.json -Dkeycloak.migration.strategy=OVERWRITE_EXISTING"]
Postgres Dockerfile
FROM postgres:9.5
# set root user details
ENV POSTGRES_PASSWORD=postgres
ENV POSTGRES_USER=postgres
ADD scripts/init.sql /docker-entrypoint-initdb.d/
# expose the 5432 port to outside the container
EXPOSE 5432
Here is a the problematic section within the standalone-ha.xml file, specifically the connection-url value.
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true"
use-java-context="true">
<connection-url>jdbc:postgresql://my-net/keycloak</connection-url>
<driver>postgresql</driver>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>keycloak</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Postgres starts fine. When I start Keycloak I get java.net.UnknownHostException: my-net. I have also tried localhost and get the same error.
Lastly I have created a user-defined bridge network as per the guide on docker networking
docker network create --driver bridge my-net
I followed the guide but I can't get keycloak to find the postgresql database. From my understanding, the network my-net should be available internally to the container running keycloak.
Any help would be greatly appreciated. Thanks
UPDATE
Postgres was started with the following:
docker run --name postgresql -p 5432:5432 --network my-net postgresql
And keycloak with:
docker run --name keycloak -p 8080:8180 --network my-net keycloak