Heroku App failed to bind to $PORT in 60 seconds

Hi all, I have a Elixir Umbrella with a Phoenix Web app that I am attempting to deploy to Heroku using Docker.

The Docker build and release succeeds; however, whenever I attempt to visit the running application I get the following error:

2019-01-16T18:11:28.595542+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

2019-01-16T18:11:28.595632+00:00 heroku[web.1]: Stopping process with SIGKILL

2019-01-16T18:11:28.685658+00:00 heroku[web.1]: Process exited with status 137

I am using Phoenix 1.4. I tried a few fixes, namely setting the http config variable correctly. My Phoenix configuration is as follows:

config :bazaar, BazaarWeb.Endpoint,
    load_from_system_env: true,
    http: [port: {:system, "PORT"}],
    url: [host: {:system, "HOST"}, port: 80],
    cache_static_manifest: "priv/static/cache_manifest.json"

The host environment variable is properly set inside the Heroku configuration. I’m not sure what else to try.

Is your docker image based on mix phx.server or are you using distillery to create an OTP release?

If your setup uses Distillery (which I strongly suggest), you are missing a few configuration like described in the guide:

  • server configures the endpoint to boot the Cowboy application http endpoint on start.
  • root configures the application root for serving static files.
  • version ensures that the asset cache will be busted on versioned application upgrades.


1 Like

try with System.get_env("PORT") instead of {:system, “PORT”}

Is there a particular reason you’re not using this buildpack? https://github.com/HashNuke/heroku-buildpack-elixir/issues/141

That’s what we use for our umbrella app running on heroku, the main part of our phoenix (1.3) config looks like this for comparison:

config :web_interface, WebInterface.Endpoint,
  load_from_system_env: true,
  http: [port: {:system, "PORT"}],
  url: [scheme: "https", host: System.get_env("HOSTNAME"), port: 443],
  force_ssl: [rewrite_on: [:x_forwarded_proto]],
  secret_key_base: System.get_env("SECRET_KEY_BASE")

It is so simple to build an OTP release with Distillery, wrap it in a Docker image and deploy a container on Heroku; there are no reason to use the buildpack-based deployment anymore.

Furthermore, mix is a development tool, that will one day support building releases. It was never intended to run production code!