How to Run Dockerized Apps on Heroku… and it’s pretty sweet

Travis Reeder
Jun 30, 2017 · 2 min read

Every cloud provider is supporting Docker now, but I have to say, Heroku nailed it. This seems to have run under the radar for the most part since I haven’t heard anyone talk about it. It reminds me of the good ol’ days when Heroku first started. Their entire pitch and tagline was git push heroku master, then magic happened. And now they’ve done the same with docker push. The only other service that is as simple is Hyper.sh, but Heroku has a few advantages like a built in load balancer, the ability to scale and many years of working out the kinks.

First, let’s start with a simple Hello World web app. This is in Go, but could be any language.

And we need a Dockerfile to build our Docker image (requires Docker 17.05+):

You can test this if you want with a simple:

docker build -t treeder/myapp .
docker run --rm -it -p 8080:8080 treeder/myapp

Then surf to http://localhost:8080 to see that it works.

Now I’ll show you two ways to deploy your app to Heroku.

This assumes you already have the Heroku CLI installed. Install the Heroku container registry plugin for the cli:

heroku plugins:install heroku-container-registry

Login to the registry:

$ heroku container:login

Now create a Heroku app:

heroku create

That command will return an app name, copy it to use it for the next command.

heroku container:push web --app ${YOUR_APP_NAME}

And boom, that’s it. It will build your image and push it to Heroku. Check out your live app with:

heroku open --app ${YOUR_APP_NAME}

The following is good if you’re deploying to Heroku with your CI tool and/or don’t want to install the Heroku CLI.

You’ll need to get your Heroku token which you can get from the cli on any machine that’s logged into Heroku:

heroku auth:token

Grab the returned token and from this point on, you don’t need Heroku CLI anymore.

Use the token to login to the Heroku Registry:

docker login --username=_ --password=${YOUR_TOKEN} registry.heroku.com

Note: The email and username are actually the underscore, don’t change those.

And then just push your image:

docker build -t registry.heroku.com/${YOUR_APP_NAME}/web .
docker push registry.heroku.com/${YOUR_APP_NAME}/web

Now surf to your Heroku app again and you’ll see it live.

Pretty dang awesome.

Travis on Docker

My posts about Docker.

Get an email whenever Travis Reeder publishes.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Medium sent you an email at to complete your subscription.

Travis Reeder

Written by

Founder, CTO at GoChain - Building and breaking things

Travis on Docker

My posts about Docker.

Travis Reeder

Written by

Founder, CTO at GoChain - Building and breaking things

Travis on Docker

My posts about Docker.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Start a blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store