MongoDB with Traefik

  docker, mongodb, traefik

I have many mongodb and i want set domain for them in traefik but it wont connect.

Traefik version: 2.5.3

My certresolver works and acme.json is not empty

Yes, my mongodb has a internal network but it wont work even in a external network or just run a mongodb

With telnet i can connect but with MongoDB compass or with writing code, i can’t connect to the database

traefik/docker-compose.yaml

version: '3.8'

services:
  traefik:
    image: traefik
    container_name: the-traefik
    network_mode: "host"
    expose:
      - 80
      - 443
      - 27017
    volumes:
      - ./traefik.yaml:/traefik.yaml
      - ./acme.json:/acme.json
      - /var/run/docker.sock:/var/run/docker.sock:ro

traefik/traefik.yaml

api:
  debug: true

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"
  mongo:
    address: ":27017"

certificatesresolvers:
  encrypt:
    acme:
      email: "***@gmail.com"
      storage: "/acme.json"
      tlschallenge: true
      httpchallenge:
        entrypoint: http

providers:
  docker:
    exposedbydefault: false

mongodb/docker-compose.yaml

version: '3.8'

services:
  mongodb-0:
      image: mongo
      container_name: mongodb-0
      environment:
        - MONGO_INITDB_ROOT_USERNAME=root
        - MONGO_INITDB_ROOT_PASSWORD=password
        - MONGO_INITDB_DATABASE=admin
      networks:
        - test
      labels:
        - traefik.enable=true
        - traefik.docker.network=test
        #
        - traefik.tcp.routers.mongo.rule=HostSNI(`test.mongo.EXAMPLE.NET`)
        - traefik.tcp.routers.mongo.entrypoints=mongo
        - traefik.tcp.routers.mongo.tls=true
        - traefik.tcp.routers.mongo.tls.certresolver=encrypt
        - traefik.tcp.routers.mongo.tls.passthrough=true
        #
        - traefik.tcp.services.mongo.loadbalancer.server.port=27017
        
networks:
  test:
    name: test
    internal: true

Update

1- I removed traefik.tcp.routers.mongo.tls.passthrough=true but in mongodb, after accept connection, it closed.
2- I added SSL=true in mongodb url and mongodb say "SSL handshake received but server is started without SSL support"

Source: Docker Questions

LEAVE A COMMENT