DEV Community

Seimei Matsusaki
Seimei Matsusaki

Posted on

Notes on Express server deployment with Docker to Heroku

Phew.. I ended up to spend the whole Saturday trying to deploy a very simple Express server to Heroku. Heroku documentation looked easy at first glance, but I got many errors and needed to do research, but I finally made the server work (src).

Here are my three notes about the deployment.
I hope these can help someone save his/her time in the future.

1. Dockerfile name needs to start with "D", not "d"

OK: "Dockerfile"
WRONG : "dockerfile"

For some reason, a Heroku CLI command heroku container:push doesn't recognize "dockerfile". You will see "No images to push" error then.

2. Use "web" as the process-type
Ref: Container Registry & Runtime (Docker Deploys)

In order to build an image and push to Heroku,
the following command is directed to use.

heroku container:push <process-type>

For a simple web-server case like mine,
"web" was the correct process type.
So, this was the correct command:

heroku container:push web

If you are wondering where "process-type" comes from,
here is an official documentation page:

Dynos and the Dyno Manager

According to it, there are three process types: "Web", "Worker", "One-off".

Since I wasn't sure what the "<process-type>" referred to, I typed an image tag at first. Yes, this was wrong. It was deployed on Heroku; however, it ended up in a "H14" "No web processes running" error.

3. Port # is given through an environment variable PORT
Ref: Setting the port for node.js server on Heroku
I wasn't sure how to publish a port on Heroku.
In short, we cannot freely publish any ports unfortunately.

instead, a port # is given through PORT variable by Heroku,
and it is what the app needed to listen to.

in my case, my app checks PORT variable when it starts,
so i didn't need any modification:

const port = process.env.PORT || 8080;

Top comments (0)