title: Docker networking - Keycloak can not connect to postgresql running in separate docker instance
body: <p>I have two docker containers, one running Keycloak 4.7.0.Final, and one running Postgresql. </p>
  
  <p>Keycloak Dockerfile</p>
  
  <pre><code>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"]
  </code></pre>
  
  <p>Postgres Dockerfile</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Here is a the problematic section within the standalone-ha.xml file, specifically the <code>connection-url</code> value.</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:datasources:5.0"&gt;
          &lt;datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true"
                          use-java-context="true"&gt;
              &lt;connection-url&gt;jdbc:postgresql://my-net/keycloak&lt;/connection-url&gt;
              &lt;driver&gt;postgresql&lt;/driver&gt;
              &lt;pool&gt;
                  &lt;max-pool-size&gt;20&lt;/max-pool-size&gt;
              &lt;/pool&gt;
              &lt;security&gt;
                  &lt;user-name&gt;keycloak&lt;/user-name&gt;
                  &lt;password&gt;sa&lt;/password&gt;
              &lt;/security&gt;
          &lt;/datasource&gt;
          &lt;drivers&gt;
              &lt;driver name="postgresql" module="org.postgresql"&gt;
                  &lt;xa-datasource-class&gt;org.postgresql.xa.PGXADataSource&lt;/xa-datasource-class&gt;
              &lt;/driver&gt;
          &lt;/drivers&gt;
      &lt;/datasources&gt;
  &lt;/subsystem&gt;
  </code></pre>
  
  <p>Postgres starts fine. When I start Keycloak I get <code>java.net.UnknownHostException: my-net</code>. I have also tried <code>localhost</code> and get the same error.</p>
  
  <p>Lastly I have created a user-defined bridge network as per the guide on <a href="https://docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks" rel="noreferrer">docker networking</a></p>
  
  <pre><code>docker network create --driver bridge my-net
  </code></pre>
  
  <p>I followed the guide but I can't get keycloak to find the postgresql database. From my understanding, the network <code>my-net</code> should be available internally to the container running keycloak.</p>
  
  <p>Any help would be greatly appreciated. Thanks</p>
  
  <h2>UPDATE</h2>
  
  <p>Postgres was started with the following:</p>
  
  <pre><code>docker run --name postgresql -p 5432:5432 --network my-net postgresql
  </code></pre>
  
  <p>And keycloak with:</p>
  
  <pre><code>docker run --name keycloak -p 8080:8180 --network my-net keycloak
  </code></pre>