Home > database >  Deploy mongo-express with cert (https) with docker-compose
Deploy mongo-express with cert (https) with docker-compose

Time:09-27

Is there option to deploy the mongo-express service with domain CERT (using HTTPS) with docker compose? I have an existing web site with CERT (It uses HTTPS) and I want to integrate the mongo-express to it. So I want to deploy it as https://my_host:8081.

My current test docker-compose.yml file works perfectly but it uses the HTTP protocol (http://localhost:8081).

My current test docker-compose.yml file:

version: "3.8"

services:
  db:
    container_name: mongo-dev
    hostname: mongo-dev
    image: mongo:4.2
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_DATABASE=auth
      - MONGO_INITDB_ROOT_PASSWORD=pass
    networks:
      - mongo-compose-network
    ports:
      - '27017:27017'
    volumes:
      - ./data:/data/db

  mongo-express:
    container_name: mongo-express
    image: mongo-express:0.54.0
    depends_on:
      - db
    networks:
      - mongo-compose-network
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongo-dev
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=pass
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=tribes
    ports:
      - '8081:8081'
    restart: on-failure

networks:
  mongo-compose-network:
    driver: bridge

I know that it can be done with NgInx but probably there is an embedded option for it. I have already read the documentation as well as the GitHub issues/pull-request but I didn't find any related topics. It is it not possible by default then I am open for a NgInx based solution.

CodePudding user response:

I have managed to solve my issue with the 1.0.0-alpha.4 Docker image version.

The service in docker-compose.yml:

  mongo-express:
    container_name: mongo-express
    hostname: mongo-express
    image: mongo-express:1.0.0-alpha.4
    depends_on:
      - mongo1
      - mongo2
    networks:
      - mongo_net
    volumes:
      - ./certs/domain.crt:/public.crt
      - ./certs/domain.key:/domain.key
    environment:
      - ME_CONFIG_MONGODB_URL=mongodb://admin:admin_pwd@mongo1:27017,mongo2:27017/?replicaSet=my-replica-set
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=admin_pwd
      - ME_CONFIG_OPTIONS_EDITORTHEME=night
      - ME_CONFIG_SITE_SSL_ENABLED=true
      - ME_CONFIG_MONGODB_ENABLE_ADMIN=true
      - ME_CONFIG_SITE_SSL_CRT_PATH=/public.crt
      - ME_CONFIG_SITE_SSL_KEY_PATH=/domain.key
    ports:
      - '8081:8081'
    restart: on-failure
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [ node.role == manager ]
    logging:
      driver: "fluentd"
      options:
        fluentd-address: ${SYSTEM_HOST}:24224
        tag: mongo-express

With the above service configuration the mongo-express will be running on https://localhost:8081 site.

NOTE:

The admin features are not available in 1.0.0-alpha.4 or latest Docker image even if ME_CONFIG_MONGODB_ENABLE_ADMIN parameter is set to true. The bug is known and it has been reported more times on GitHub. Eg.: https://github.com/mongo-express/mongo-express/issues/647. I am waiting for the fix...

  • Related