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

DockerHerokuDocker ComposeDockerfile

Docker Problem Overview


I currently have a locally tested and working web app that consists of 4 docker containers: Java MVC, NodeJS, Flask, and MongoDB. I have 4 Dockerfiles, one for each, and I manage the builds with docker-compose.yml.

However, now I want to push my code to Heroku and I read the documentation at https://devcenter.heroku.com/articles/container-registry-and-runtime. However, it seems very ambigious about how to use docker-compose on the production line. This is what it says on the docs:

"If you’ve created a multi-container application you can use Docker Compose to define your local development environment. Learn how to use Docker Compose for local development."

Can anyone guide me to some actual code of how I can push my project to the Heroku Container using Heroku's CLI?

Docker Solutions


Solution 1 - Docker

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.

Solution 2 - Docker

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. Heroku 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.

Solution 3 - Docker

Yet another update on this question, as I was looking into it and found out that Heroku now officially supports docker-compose.

Please follow this guide: Local Development with Docker Compose

Worth noting that, as Heroku is non-persistent, the guide above recommends you to use official docker images of (redis, postgres, etc.) for local development, but use Heroku's offerings when deploying on it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAspiringMatView Question on Stackoverflow
Solution 1 - DockerAspiringMatView Answer on Stackoverflow
Solution 2 - DockereliotnView Answer on Stackoverflow
Solution 3 - DockerGrimlockView Answer on Stackoverflow