Docker Community Forums

Share and learn in the Docker community.

Can't access mongos router from another container

I’ve got my docker image that extends from mongo:4.4.4. In this image, I’m running an entrypoint that runs a script for configuring my mongos router. The final command I use is

mongos --configdb $CONFIG_DB \
 	   --port 27017 \
 	   --bind_ip 0.0.0.0 \
 	   --tlsMode requireTLS \
 	   --tlsAllowConnectionsWithoutCertificates \
 	   --tlsCAFile=./etc/mongodb/ssl/ca.crt \
 	   --tlsCertificateKeyFile=./etc/mongodb/ssl/cert.pem \
 	   --tlsClusterFile=./etc/mongodb/ssl/cert.pem \
 	   --slowOpSampleRate 0.1 \
 	   --slowms 200 \
 	   --clusterAuthMode=x509

My image builds correctly.
I have a docker-compose file that builds my golang image, and mongo image and then runs the container. Looks like this

version: '3'

services:
  go:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: torchwood
      ports:
        - 8080:8080
      depends_on:
        - mongo

  mongo:
    build:
      context: .
      dockerfile: mongos.Dockerfile
    container_name: mongos-router
    ports:
      - 20000:27017

Running docker-compose command will get me my two containers, and put them in the new docker network.
The issue I have is that my golang app container cannot access the mongos router container.

I can connect to the mongos router from my localhost with

mongo mongodb://localhost:20000 --tls --tlsCAFile --tlsCertificateKeyFile

But In my app, I’ve got my connection string that looks like this (not full connection string)

mongodb://mongos-router:27017/torchwood

And I cant connect.

Confirming the docker network made, I see both containers there, and when my app fails, that container gets removed from the containers list from the docker network inspect command.

To add more info, my app gives: context deadline exceeded when pinging the mongo client