简体   繁体   English

如何在 docker 集群模式中的 docker-compose.yml 中的 traefik 后面配置 mongodb?

[英]how to config mongodb behind traefik in docker-compose.yml in docker swarm mode?

services:
    db:
        image: mongo:4.4-bionic
        logging: *logging
        environment:
            - MONGO_INITDB_ROOT_USERNAME=username
            - MONGO_INITDB_ROOT_PASSWORD=password
        command: mongod --replSet "rs0" --bind_ip_all --port 27017
        deploy:
            labels:
                - traefik.tcp.routers.db-1.entrypoints=https
                - traefik.tcp.routers.db-1.rule=HostSNI(`example.com`)
                - traefik.tcp.routers.db-1.tls=true
                - traefik.tcp.routers.db-1.tls.certresolver=letsencrypt
                - traefik.tcp.routers.db-1.tls.domains[0].main=example.com
                - traefik.tcp.services.db-1.loadbalancer.server.port=27017
        volumes:
            - db:/data
        networks:
            - main

The above is part of my whole config.以上是我整个配置的一部分。 I can't access the db through我无法通过

mongo -u username -p password --host example.com --port 443

I have no idea what's wrong... It suspend on我不知道出了什么问题...它暂停

connecting to: mongodb://example.com:443/?compressors=disabled&gssapiServiceName=mongodb

At a high level what you need from Traefik Traefik 的高水平需求

  1. create an entry point TCP port 27017 --entrypoints.mongo.address=:27017创建入口点 TCP 端口 27017 --entrypoints.mongo.address=:27017
  2. export your port 27017 so that your client can connect to Traefik导出您的端口27017以便您的客户端可以连接到 Traefik
  3. tell your Mongo container that is a TCP service with a router and enable it.告诉你的 Mongo 容器是一个带有路由器的 TCP 服务并启用它。
  4. check your Traefik dashboard for new TCP services检查您的 Traefik 仪表板以获取新的 TCP 服务

Try this after you expose port 27017 on your traefik container and add an entry point `--entrypoints.mongo.address=:27017'在 traefik 容器上公开端口27017并添加入口点 `--entrypoints.mongo.address=:27017' 后尝试此操作

db:
    image: mongo:4.4-bionic
    logging: *logging
    environment:
        - MONGO_INITDB_ROOT_USERNAME=username
        - MONGO_INITDB_ROOT_PASSWORD=password
    command: mongod --replSet "rs0" --bind_ip_all --port 27017
    deploy:
        labels:
            - traefik.enable=true
            - traefik.tcp.routers.db-1.entrypoints=mongo
            - traefik.tcp.routers.db-1.service=mongo
            - traefik.tcp.routers.db-1.rule=HostSNI(`example.com`)
            - traefik.tcp.routers.db-1.tls=true
            - traefik.tcp.routers.db-1.tls.certresolver=letsencrypt
            - traefik.tcp.routers.db-1.tls.domains[0].main=example.com
            - traefik.tcp.services.db-1.loadbalancer.server.port=27017
    volumes:
        - db:/data
    networks:
        - main

PS. PS。 you might want to change the port and think about how to limit external access to your db.您可能想要更改端口并考虑如何限制对您的数据库的外部访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM