Graylog docker did not connect to MongoDB docker

(Gabriel Lindoso) #1

I’m trying to connect a 2-server Graylog docker in a MongoDB replica set, also in docker. MongoDB replica set is working OK.

IMAGE               PORTS                                  NAMES
mongo     >27017-27019/tcp   mongo

[ReplicaSetMonitor-TaskExecutor] Successfully connected to server-1:27017 (1 connections now open to server-1:27017 with a 5 second timeout)  
[LogicalSessionCacheRefresh] Successfully connected to server-2:27017 (1 connections now open to server-2:27017 with a 5 second timeout)  
[ReplicaSetMonitor-TaskExecutor] Successfully connected to server-3:27017 (1 connections now open to server-3:27017 with a 5 second timeout)  
Starting new replica set monitor for graylog_prd_1/server-2:27017,server-3:27017,server-1:27017

But, when I execute a docker run command, it didn’t find the mongo.

sudo docker run -d -e TZ=America/Sao_Paulo --restart always --name graylog -p 80:9000 -p 514:514 -p 514:514/udp -p 12201:12201 -p 12201:12201/udp -v /opt/open/graylog:/usr/share/graylog graylog/graylog:2.5 && sudo docker logs -f graylog &

Cluster created with settings {hosts=[mongo:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=mongo:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Exception in monitor thread while connecting to server mongo:27017 com.mongodb.MongoSocketException: mongo: Name or service not known

I’ve tried to use all 3 config modes in the graylog.conf, but none of them seens to work.

# MongoDB connection string
mongodb_uri = mongodb://server-1:27017/graylog_prd_1

# Authenticate against the MongoDB server
mongodb_uri = mongodb://admin:graylog@server-1:27017/graylog_prd_1

# Use a replica set instead of a single host
mongodb_uri = mongodb://admin:graylog@server-2,server-3,server-1:27017/?replicaSet=graylog_prd_1

Seens that Graylog is trying to connect to a local MongoDB. Have I missed anything in docker run command that allows the connection?
I’ve followed the instructions from MongoDB site and Graylog site, and have searched hundreds of sites, but nothing solve my problem.
I can connect to MongoDB via telnet,

[user@server-2 ~]$ telnet localhost 27017
Connected to localhost.
Escape character is '^]'.

[user@server-2 ~]$ telnet 27017
Connected to
Escape character is '^]'.

Thanks in advance.

Server-1: MongoDB Service Master
Server-2: MongoDB replica / Graylog Server 1
Server-3: MongoDB replica / Graylog Server 2

(Jan Doberstein) #2

when you use DNS in your configuration you need to make sure all servers can resolve that in the same way. You are using Names in the configuration and for example IP in your telnet session.

In addition you need to have ONE monodb_uri string and not 3 - in addition I do mot see how you provide the configuration to Graylog. Please read the docker instalaltion manual again