如何设置TCP服务后端?

时间:2019-05-02 23:00:43

标签: docker traefik

我有一个通过docker-compose开始并由traefik管理的MQTT经纪人:

  mqtt:
    container_name: mqtt
    image: eclipse-mosquitto
    restart: always
    labels:
      - 'traefik.port=1883'
      - 'traefik.frontend.rule=Host:mqtt2.ex.com'
      - 'traefik.frontend.entryPoints=mqtt'
    ports:
      - 3883:1883

我正在尝试设置后端的traefik.toml的相关部分:

[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.mqtt]
address = ":2884"

[tcp] # YAY!
   [tcp.routers]
      [tcp.routers.mqtt]
         entrypoints = ["mqtt"]
         rule = "HostSNI(`*`)" # Catches every request       
         service = "mqtt"
   [tcp.services]
   [tcp.services.mqtt.LoadBalancer]


I can access the broker via port `3883` but this is not what I intend to do (the exposed port above is just to make sure that the container is OK): I would like to proxy it though `traefik` like all my other **HTTP** services.

This however is not a HTTP service, it is a TCP one and my problem is that **I do not know how to configure such a TCP backend**.

documentation对该功能的要求很低,只是指出

  

当前,LoadBalancer是唯一受支持的TCP服务。   但是,由于Traefik是一个不断发展的项目,因此其他类型的TCP   将来会提供服务,因此您必须   指定它。

就配置后端而言,这意味着什么?我应该在docker-compose.yamltraefik.toml中添加些什么,以使后端被识别为TCP服务?目前,它被视为HTTP,并且代理无效:

enter image description here

0 个答案:

没有答案