Cannot connect to MongoDB v6 in docker in ec2 after enabling SSL/TLS in .NET core app

Hello,
I think I am bit confused on MongoDB v& in docker with TLS enabled. Everything seems to be working fine on the EC2 instance and also with those public key on my local MongoDB Compass tool.
But come to my .NET application, it is not connecting.
I have tried everything and I need some help with connection string.
Here is the Code:

string conn = @"mongodb://username:Password@ec2instance.compute.amazonaws.com:27017/?tls=true&authMechanism=SCRAM-SHA-1";
var clientSettings = MongoClientSettings.FromUrl(new MongoUrl(conn));
clientSettings.AllowInsecureTls = true;
clientSettings.DirectConnection = true;
                clientSettings.Scheme = ConnectionStringScheme.MongoDB;
                clientSettings.UseTls = true;
                clientSettings.ServerApi = new ServerApi(ServerApiVersion.V1);
                SslSettings sslSettings = new SslSettings
                {
                    ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true,
                    CheckCertificateRevocation = false,
                    EnabledSslProtocols = SslProtocols.Tls12,
                    ClientCertificates = new List<X509Certificate>() {
                                                    new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + @"Files\intermediate_pfx.pfx", "Phaseuser")
                                                },
                    ClientCertificateSelectionCallback = (sender, host, certificates, certificate, issuers) => clientSettings.SslSettings.ClientCertificates.ToList()[0],
                };

                clientSettings.SslSettings = sslSettings;
                MongoClient client = new MongoClient(clientSettings);
                var dbList = client.ListDatabases().ToList();

and here is my compose.yaml file:

services:
  mongo:
    image: mongo
    command: ["--bind_ip_all", "--tlsMode", "requireTLS", "--tlsCAFile", "/usr/local/ca-certificates/root_ca.crt", "--tlsCertificateKeyFile", "/run/secrets/server-certificate"]
    environment:
      MONGO_INITDB_ROOT_USERNAME: username
      MONGO_INITDB_ROOT_PASSWORD: Password
    restart: always
    volumes:
      - $PWD/ca-certs:/usr/local/ca-certificates
      - $PWD/db:/data/db
    secrets:
      - server-certificate
    ports:
      - '27017-27019:27017-27019'

secrets:
  server-certificate:
    file: mongo.pem

Everytime when I tried to connect to it, its says timeout.
Any suggestions would be really helpful.