mongo-express: Problem connecting to mongo with ssl

Hi.

My docker compose section looks like so:

  fn-mongo-express-web:
    container_name: fn-mongo-express-web
    image: mongo-express
    networks: 
      - internal
    ports:
      - "127.0.0.1:8081:8081"
    volumes:
      - "./etc/ssl/db-client.ca.crt:/etc/db-client.ca.crt:ro"
    environment:
      - "ME_CONFIG_MONGODB_SSLVALIDATE=false"
      - "ME_CONFIG_MONGODB_CA_FILE=/etc/db-client.ca.crt"
    links:
      - fn-profiles-mongo:mongo
    depends_on:
      - fn-profiles-mongo
    restart: always

The container complains as follows:

fn-mongo-express-web    | Waiting for mongo:27017...
fn-mongo-express-web    | Welcome to mongo-express
fn-mongo-express-web    | ------------------------
fn-mongo-express-web    |
fn-mongo-express-web    |
fn-mongo-express-web    | Mongo Express server listening at http://0.0.0.0:8081
fn-mongo-express-web    | Server is open to allow connections from anyone (0.0.0.0)
fn-mongo-express-web    | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
fn-mongo-express-web    |
fn-mongo-express-web    | /node_modules/mongodb/lib/server.js:265
fn-mongo-express-web    |         process.nextTick(function() { throw err; })
fn-mongo-express-web    |                                       ^
fn-mongo-express-web    | MongoError: connection 0 to mongo:27017 closed
fn-mongo-express-web    |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:29:11)
fn-mongo-express-web    |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:200:22)
fn-mongo-express-web    |     at Object.onceWrapper (events.js:315:30)
fn-mongo-express-web    |     at emitOne (events.js:116:13)
fn-mongo-express-web    |     at Socket.emit (events.js:211:7)
fn-mongo-express-web    |     at TCP._handle.close [as _onclose] (net.js:561:12)

Help anybody?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I am using the current mongo express release on AWS Document DB passing the PEM as CA for the mongo connection and it’s working just fine. @rtritto you can close this.

So I’ll answer it myself 😛

In case of using pem file, you also have to split certs properly…

module.exports = {
  mongodb: {
    ssl: true,
    sslValidate: true,
    sslCA: require('fs').readFileSync(process.env.ME_CONFIG_MONGODB_CA_FILE).toString()
        .split('-----END CERTIFICATE-----').map(c=>c.concat('-----END CERTIFICATE-----'))
  }
};