I am trying to use JDBC from first container to connect to Postgresql database on secend container .the error happens while trying to make a database connection.
 conn = DriverManager.getConnection(url, user, password);
I deploy war file into wildfly that is docker container.
when I call the connect() method the error  occur.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.corsan</groupId>
    <artifactId>corsan</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.16</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
docker file:
FROM jboss/wildfly
ADD corsan.war /opt/jboss/wildfly/standalone/deployments/
the Java code for JDBC connection:
private final String url = "jdbc:postgresql://localhost:5432/postgres";
private final String user = "postgres";
private final String password = "1234";
    public Connection connect() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("Connected to the PostgreSQL server successfully.");
        } catch (SQLException e) {
            System.out.println("problem while making connection");
            System.out.println(e.getMessage());
        }
        return conn;
    }
and while the wildfly is lunching there is always this warning that I guess is relevant to the connection refused Error:
Could not index class org/postgresql/jdbc/PgConnection$1.class at /content/corsan.war/WEB-INF/lib/postgresql-42.2.16.jar: java.lang.IllegalStateException: Required class information is missing
these two picture are intellij project structure and artifact that has postgres driver library in its lib.
Project structure
Project structure Artifact
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
22:51:20,921 ERROR [io.undertow.request] (default task-1) 
  UT005023: Exception handling request to /corsan/: java.lang.NullPointerException  
when I deploy the war directly to the same application server in local it works fine. But when I use docker container this issue occure. I appreciate for any hint or help.
Postgresql and application server are running in separate container in local machine. docker ps :
app server port: 0.0.0.0:8080->8080/tcp
PG: 0.0.0.0:5432->5432/tcp
