title: Keycloak docker service cannot connect to database
body: <p>I am new to docker and I want to start a keycloak container with docker-compose. I am using a mariadb and database starts successfully. But when starting keycloak container it gives this error.</p>
  <blockquote>
  <p>Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=project-db)(port=3308)(type=master) : Socket fail to connect to host:project-db, port:3308. Connection refused (Connection refused)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:241)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1243)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:622)
  at org.mariadb.jdbc//org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:142)
  at org.mariadb.jdbc//org.mariadb.jdbc.Driver.connect(Driver.java:86)
  at org.jboss.ironjacamar.jdbcadapters@1.4.20.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
  ... 57 more
  Caused by: java.sql.SQLNonTransientConnectionException: Socket fail to connect to host:project-db, port:3308. Connection refused (Connection refused)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:241)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.connException(ExceptionMapper.java:87)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createSocket(tocol.java:218)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:474)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1238)
  ... 61 more
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
  at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
  at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
  at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
  at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
  at java.base/java.net.Socket.connect(Socket.java:609)
  at org.mariadb.jdbc//org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createSocket(AbstractConnectProtocol.java:213)
  ... 63 more</p>
  </blockquote>
  <p>This is my docker-compose.</p>
  <pre><code>version: &quot;3.6&quot;
  services:
    project-db:
      container_name: project-maria-db
      image: mariadb:10.5.8-focal
      restart: always
      ports:
        - 3308:3306
      volumes:
        - /project/db:/data/db
      environment:
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_DATABASE=project
        - MYSQL_USER=user
        - MYSQL_PASSWORD=password
  
    project-keycloak:
      container_name: project-keycloak
      image: quay.io/keycloak/keycloak:10.0.1
      restart: always
      ports:
        - 8180:8080
      environment:
        PROXY_ADDRESS_FORWARDING: &quot;true&quot;
        DB_VENDOR: mariadb
        DB_ADDR: project-db
        DB_PORT: 3308
        DB_DATABASE: project_keycloak
        DB_USER: user
        DB_PASSWORD: password
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: admin
      depends_on:
        - project-db
  </code></pre>
  <p>can someone help me to solve this issue?</p>