Graylog can't connect to mongodb container

I can’t connect my graylog container with mongodb. Each container is running, but I get error in graylog:

2023-04-13 13:07:00,602 INFO : org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|legacy", "version": "4.7.1"}, "os": {"type": "Linux", "name": "Linux", "architecture": "amd64", "version": "5.19.0-38-generic"}, "platform": "Java/Eclipse Adoptium/17.0.6+10"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=null, userName='graylog', source='graylog', password=<hidden>, mechanismProperties=<hidden>}, streamFactoryFactory=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.Jep395RecordCodecProvider@772861aa]}, clusterSettings={hosts=[mongo:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=1000, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=null, autoEncryptionSettings=null, contextProvider=null}
2023-04-13T13:07:00.620457410Z 2023-04-13 13:07:00,620 INFO : org.mongodb.driver.cluster - Cluster description not yet available. Waiting for 30000 ms before timing out
2023-04-13T13:07:10.631796188Z 2023-04-13 13:07:10,618 INFO : org.mongodb.driver.cluster - Exception in monitor thread while connecting to server mongo:27017
2023-04-13T13:07:10.631837021Z com.mongodb.MongoSocketOpenException: Exception opening socket
2023-04-13T13:07:10.631847816Z  at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[graylog.jar:?]
2023-04-13T13:07:10.631856020Z  at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:180) ~[graylog.jar:?]
2023-04-13T13:07:10.631863303Z  at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:193) [graylog.jar:?]
2023-04-13T13:07:10.631870507Z  at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:157) [graylog.jar:?]
2023-04-13T13:07:10.631891681Z  at java.lang.Thread.run(Unknown Source) [?:?]
2023-04-13T13:07:10.631900455Z Caused by: java.net.SocketTimeoutException: Connect timed out
2023-04-13T13:07:10.631907101Z  at sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source) ~[?:?]
2023-04-13T13:07:10.631913863Z  at sun.nio.ch.NioSocketImpl.connect(Unknown Source) ~[?:?]
2023-04-13T13:07:10.631920435Z  at java.net.SocksSocketImpl.connect(Unknown Source) ~[?:?]
2023-04-13T13:07:10.631927792Z  at java.net.Socket.connect(Unknown Source) ~[?:?]
2023-04-13T13:07:10.631934758Z  at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107) ~[graylog.jar:?]
2023-04-13T13:07:10.631942570Z  at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[graylog.jar:?]
2023-04-13T13:07:10.631950098Z  at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[graylog.jar:?]
2023-04-13T13:07:10.631957216Z  ... 4 more
2023-04-13T13:07:30.623275709Z 2023-04-13 13:07:30,622 INFO : org.graylog2.bootstrap.preflight.MongoDBPreflightCheck - MongoDB is not available. Retry #1

because of what it can be?

docker-compose.yaml

version: "3.9"

#Docker Networks
networks:
  network:
    driver: bridge

volumes:
  es_data:
  mongo_data:
  graylog_data:
  graylog_journal:

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.7.0
    container_name: elasticsearch_1
    environment:
      - http.host=0.0.0.0
      - transport.host=localhost
      - network.host=0.0.0.0
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    deploy:
      resources:
        limits:
          memory: 1g
    networks:
      - network
    volumes:
      - es_data:/usr/share/elasticsearch/data

  mongo:
    image: mongo:latest
    container_name: mongo_1
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: secret
    ports:
      - "27017:27017"
    expose:
      - 27017
    networks:
      - network
    volumes:
      - ./init/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js
      - mongo_data:/data/db

  graylog:
    image: graylog/graylog:5.0.6
    container_name: graylog_1
    environment:
      - GRAYLOG_PASSWORD_SECRET=passwordforgraylog
      - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
      - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
      - GRAYLOG_ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - GRAYLOG_MONGODB_URI=mongodb://graylog:secret@mongo:27017/graylog
    entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 --  /docker-entrypoint.sh
    volumes:
      - graylog_data:/usr/share/graylog/data/data
      - graylog_journal:/usr/share/graylog/data/journal
    links:
      - mongo:mongo
      - elasticsearch
    depends_on:
      - mongo
      - elasticsearch
    ports:
      - "9000:9000"
      - "1514:1514"
      - "1514:1514/udp"
      - "12201:12201"
      - "12201:12201/udp"
      - "5555:5555"
    restart: always
    networks:
      - network

init-mongo.js

graylog = db.getSiblingDB('graylog');
graylog.createUser(
    {
        user: "graylog",
        pwd: "secret",
        roles: [
            { role: "dbOwner", db: "graylog" }
        ]
    }
);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.