Skip to content

Instantly share code, notes, and snippets.

@vgunawan
Last active August 18, 2022 21:06
Show Gist options
  • Save vgunawan/4588cf26ca84ba57e39008d94dae032a to your computer and use it in GitHub Desktop.
Save vgunawan/4588cf26ca84ba57e39008d94dae032a to your computer and use it in GitHub Desktop.
Elixir Mongo TCP connect: unknown POSIX error
version: '3.3'
services:
db_1:
image: mongo:3.0
expose:
- "27017"
command: --replSet murmur --storageEngine wiredTiger --noauth
networks:
- skynet
ports:
#these ports are opened for using mongo client on host machine
- "37017:27017"
db_2:
image: mongo:3.0
expose:
- "27017"
command: --replSet murmur --storageEngine wiredTiger --noauth
networks:
- skynet
ports:
#these ports are opened for using mongo client on host machine
- "37117:27017"
db_backup:
image: mongo:3.0
expose:
- "27017"
command: --replSet murmur --storageEngine wiredTiger --noauth
networks:
- skynet
ports:
#these ports are opened for using mongo client on host machine
- "37217:27017"
networks:
skynet:
  1. Run docker compose to start up all mongo nodes
  2. Connect to db_1 node using mongo -p 37017, got to have mongo client installed locally. You could also docker exec.
  3. Run mongo-replicaset-instruction.js in the mongo shell, this configure the replica set.
  4. Run your docker supplying --networks arguments to join the above network
  5. Before running your application on docker on step 4, run echo "1.1.1.1 db_backup" >> /etc/hosts to point it to non existant destination.
  6. Run your app in the docker container you started on step 4.
  7. All goes well you should see these messages
23:23:31.799 [error] Mongo.Protocol (#PID<0.643.0>) failed to connect: ** (Mongo.Error) tcp connect: unknown POSIX error - :timeout
 
23:23:31.800 [error] GenServer #PID<0.643.0> terminating
** (stop) exited in: :gen_server.call(#PID<0.643.0>, {:checkout, #Reference<0.3803180105.3846438913.42441>, true, 5000}, 5000)
    ** (EXIT) time out
Last message: []
State: Mongo.Protocol
rs.initiate()
rs.add("db_2")
rs.add("db_backup")
conf=rs.conf()
conf.members[2].priority = 0
rs.reconfig(conf)
@thomasdornpearson
Copy link

Did you solve this problem. I am facing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment