How to push Docker containers managed by Docker-compose to Heroku? How to push Docker containers managed by Docker-compose to Heroku? heroku heroku

How to push Docker containers managed by Docker-compose to Heroku?


Just an update on this question since it seems to be getting a lot of traction lately.

There is now an officially supported "Heroku.yml" solution offered by Heroku. You can now write a .yml file (with a format similar to docker-compose) and Heroku will work out your images. Just follow the link above for details.

Happy Heroku-ing.


The more accurate heroku documentation for what you are looking to do is here:https://devcenter.heroku.com/articles/container-registry-and-runtime

The above will walk you through setting up the heroku container plugin and logging into the registry. You can even migrate an image to a Dockerfile with the following line in your dockerfile:

FROM "<insert Dockerfile tag here>"

To easily set this up, you will name your Dockerfiles with different suffixes, such as Dockerfile.mongo, Dockerfile.node, Dockerfile.flask, and Dockerfile.javamvc. The suffix tells heroku the dyno name used for your web app. When you need to push all of your containers, you can do so with the following command, which will recursively build all dockerfiles as long as all of them have unique suffixes:

heroku container:push --recursive

As Heroku doesn't read docker-compose files, any environment variable setup/port exposure/etc will need to be migrated to the Dockerfile. Also as I can't find how to do persistent storage/volume mounting with containers on Heroku, I would recommend using a Heroku add-on for your mongo database.

On Heroku, you will see your app running as one dyno per Dockerfile, with each dyno's name as the suffix of each Dockerfile.

UPDATE:

  1. Travis brings up a good point. Make sure to have a CMD statement in your Dockerfile, otherwise heroku will throw an error.
  2. Yesterdayeroku also recently added a step to the process, you will need to run heroku container:release <your dyno name> for each dyno that you want to update.