AspiringMat
AspiringMat

Reputation: 2279

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

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?

Upvotes: 62

Views: 45229

Answers (3)

Grimlock
Grimlock

Reputation: 1091

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.

Upvotes: 0

eliotn
eliotn

Reputation: 300

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.

Upvotes: 13

AspiringMat
AspiringMat

Reputation: 2279

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.

Upvotes: 26

Related Questions