Docker Community Forums

Share and learn in the Docker community.

Configure mongos router from docker

I’m trying to configure a mongos router through docker, that I’ll then connect to from my localhost.
While configuring the mongos router, I’m using mongos --config <path to file> to specify my config file
Dockerfile

FROM mongo:4.4.4

COPY mongos.conf /etc/mongos.conf

# TLS CA Root file
COPY ca.crt /etc/mongodb/ssl/ca.crt
# TLS Certificate key file
COPY cert.pem /etc/mongodb/ssl/cert.pem

CMD [ "mongos", "--config", "/etc/mongos.conf" ]

mongos.conf file

net:
  bindIp: 0.0.0.0
  port: 27017
  tls:
    CAFile: /etc/mongodb/ssl/ca.crt
    certificateKeyFile: /etc/mongodb/ssl/cert.pem
    clusterFile: /etc/mongodb/ssl/cert.pem
    mode: requireTLS
processManagement:
  fork: true
security:
  clusterAuthMode: x509
setParameter:
  authenticationMechanisms: SCRAM-SHA-256,MONGODB-X509
sharding:
  configDB: <my configdb replica set>
systemLog:
  destination: file
  path: /var/log/mongodb/mongos.log

When I run my container from the built image, I just get:

about to fork child process, waiting until server is ready for connections.

forked process: 9

child process started successfully, parent exiting

Which is weird. Normally, running mongos --config <path to file> from my terminal starts my mongos service with logs getting put out like so

$ mongos --config mongos.conf
{"t":{"$date":"2021-04-20T18:30:46.416+03:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-04-20T18:30:46.717+03:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"mongosMain","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","modules":[],"allocator":"tcmalloc","environment":{"distmod":"windows","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-04-20T18:30:46.717+03:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"mongosMain","msg":"Operating System","attr":{"os":{"name":"Microsoft Windows 10","version":"10.0 (build 18363)"}}}
{"t":{"$date":"2021-04-20T18:30:46.717+03:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"mongosMain","msg":"Options set by command line","attr":{"options":{"config":"mongos.conf","net":{"bindIp":"0.0.0.0","port":27017,"tls":{"CAFile":"ca.crt","certificateKeyFile":"cert.pem","clusterFile":"cert.pem","mode":"requireTLS"}},"security":{"clusterAuthMode":"x509"},"setParameter":{"authenticationMechanisms":"SCRAM-SHA-2

, but running from docker, I’m not sure what I’m doing wrong.

Taking this fields away from the config file fixes issue.