How to setup grafana on heroku?

I’m trying to setup grafana on heroku but I cant get it to work. What I did is the following:

Premade Docker Container

I tried to release the premade docker container “grafana/grafana”. This is what I did:

  • heroku stack:set container -a <app>
  • docker tag grafana/grafana<app>/web
  • docker push<app>/web
  • heroku container:release web -a <app>

When executing the release command, heroku gave me the following response:

Releasing images web to <app>... !
 ▸    No command specified for process type web

So that didn’t work.

Building my own image

I stumbled upon a few stackoverflow threads of users who had the same problem, specifically this one that suggested that I replace ENTRYPOINT with CMD in the Dockerfile, so I cloned the grafana/grafana repository and did just that. After that I built the container by saying docker build -t grafana/grafana:dev .. That worked fine and I used the same commands as above (replacing grafana/grafana with grafana/grafana:dev) to release the container to heroku and this time it worked, however after 60 seconds the container gets killed because Web process failed to bind to $PORT within 60 seconds of launch.

Now I am familiar with this error, what it means is that the application fails to start listening to the port heroku dynamically provides it via the PORT environment variable. The port is not necessarily the same each time so I can’t hardcode it.

How can I get the grafana server to listen to the PORT variable?