[英]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 的高水平需求
--entrypoints.mongo.address=:27017
--entrypoints.mongo.address=:27017
27017
so that your client can connect to Traefik27017
以便您的客户端可以连接到 TraefikTry 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.