Parse Server keep loosing the DB connection after 30 seconds or so

I have the fallowing docker compose file:

version: '3.9'

services:
  database:
    image: mongo:3.7
    restart: on-failure
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: admin
    volumes:
      - ./mongodb/data:/data/db

  server:
    image: parseplatform/parse-server:5.2.3
    restart: on-failure
    ports:
      - 1337:1337
    environment:
      - PARSE_SERVER_APPLICATION_ID=$SERVER_APPLICATION_ID
      - PARSE_SERVER_APPLICATION_NAME=$SERVER_APPLICATION_NAME
      - PARSE_SERVER_MASTER_KEY=$SERVER_MASTER_KEY
      - PARSE_SERVER_DATABASE_URI=mongodb://admin:admin@mongo/parse_server?authSource=admin?directConnection=true
      - PARSE_SERVER_MOUNT_GRAPHQL=true
      - PARSE_SERVER_CLOUD=/parse-server/cloud/main.js
      - PARSE_SERVER_GRAPH_QLSCHEMA=/parse-server/cloud/schema_2.graphql
      - PARSE_SERVER_DIRECT_ACCESS=true
    links:
      - database:mongo
    depends_on:
      - database
    volumes:
      - parse_server_cloud:/parse-server/cloud

volumes:
  mongo_data:
  parse_server_cloud:
    driver: local
    driver_opts:
      type: none
      device: ../src
      o: bind

If I am running it via docker-compose up everything is going to run ok, but after a little while (about 30sec to 1min) I will get the fallowing error:

server_1         | MongoServerSelectionError: Server selection timed out after 30000 ms
server_1         |     at Timeout._onTimeout (/parse-server/node_modules/mongodb/lib/sdam/topology.js:312:38)
server_1         |     at listOnTimeout (node:internal/timers:559:17)
server_1         |     at processTimers (node:internal/timers:502:7) {
server_1         |   reason: TopologyDescription {
server_1         |     type: 'Unknown',
server_1         |     servers: Map(1) { 'mongo:27017' => [ServerDescription] },
server_1         |     stale: false,
server_1         |     compatible: true,
server_1         |     heartbeatFrequencyMS: 10000,
server_1         |     localThresholdMS: 15,
server_1         |     logicalSessionTimeoutMinutes: undefined
server_1         |   }
server_1         | }

I’ve also tried multiple version of mongodb and also of parse-server but is get the same error every single time after a while.

The interesting thing is that I did not get this error on PopOS 22.04 but I am getting this on Ubunut 22.10 which I am running it right now. Could any of you tell me what should I do?

OS: Ubunut 22.10

Docker: version 23.0.2, build 569dd73


UPDATE:

I’ve tried so far the fallowing:


Option 1:

Removing the ?directConnection=true from the PARSE_SERVER_DATABASE_URI


Option 2:

Using a postgress service via docker compose like this:


  database:
    image: postgres:13.2
    ports:
      - 5432:5432
    environment:
        POSTGRES_USER: admin
        POSTGRES_PASSWORD: admin

Also update the PARSE_SERVER_DATABASE_URI with postgres://admin:admin@database:5432/parse_server?authSource=admin.
And I still get this error of connection:

Error: connect ETIMEDOUT 172.24.0.2:5432
     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
   errno: -110,
   code: 'ETIMEDOUT',
   syscall: 'connect',
   address: '172.24.0.2',
  port: 5432
}