herokumqttmosquittobroker

Deploy mosquitto container to heroku


Long story short, I've been trying to deploy a mosquitto mqtt broker to heroku. After several days and a lot of browsing, reading docs and other SO questions I just can't get it to work. The broker image does work locally but whenever I upload it to heroku, the log shows an R10 and H20 error (the "app boot timeout" one) which is my only clue to as to why this isn't working. I used docker to create an image of the mosquitto broker with this docker-compose.yml config file:

version: '3'

services:
  mqtt:
    container_name: mqtt
    image: eclipse-mosquitto:latest
    restart: unless-stopped
    ports:
      - 1883:1883
      - 9001:9001
    volumes:
      - /MYPATH/mosquitto/config:/mosquitto/config
      - /MYPATH/mosquitto/data:/mosquitto/data
      - /MYPATH/mosquitto/log:/mosquitto/log
volumes:
  config:
  data:
  log:

Here I've tried removing the ports and adding network_mode: "host" as seen in another question but to no avail.

My mosquitto.conf is like this:

listener 1883 0.0.0.0
protocol websockets
persistence true
persistence_location /mosquitto/data
allow_anonymous true

I'm only trying the basics here, not even password or anything until I can get this to work. To deploy I go with

heroku login heroku container:login docker tag APPNAME registry.heroku.com/APPNAME/web docker registry.heroku.com/APPNAME/web heroku container:release --app APPNAME web

Please I'd appreciate any input on this, as anything I've seen similar to this hasn't worked.

Similar questions I've tried to adapt to my "solution":


Solution

  • Unfortunately, as of June 2022, it isn't possible to do non-http traffic on (free) heroku dynos without paying for an add-on specifically designed to work around the architecture of heroku, e.g. https://devcenter.heroku.com/articles/cloudmqtt.

    About the architecture that prevents arbitrary protocols: Deploying a TCP server to Heroku

    Similar issues on AWS: Can AWS Lambdas receive inbound TCP connections?

    As for paid tiers, it is unclear whether heroku supports them, because heroku's pricing site details seem to imply there are more networking capabilities / dedicated resources in higher tiers, but TCP isn't explicitly mentioned there either. https://www.heroku.com/pricing (click "see full specs" to see this ambiguity.)