59

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?

4
  • Have you created a docker-compose.yml file? If you have Dockerfile to create the docker images to your applications and ports you want to expose and volumes you want to mount. we can create a docker-compose.yml
    – Jinna Balu
    Oct 24, 2017 at 12:56
  • If your applications are dependent on each other we can create compose for all otherwise you have to create the individual docker-compose.yml files
    – Jinna Balu
    Oct 24, 2017 at 12:58
  • 6
    @JinnaBalu I already have a docker-compose.yml. However, I am looking for a way to finally push my code to Heroku since the docs are very ambiguous on it. Oct 24, 2017 at 12:58
  • hi @AspiringMat. Did you solve the issue? I'm also checking a way to deploy on heroku a container create by compose, with volumes
    – DeLac
    Sep 15, 2022 at 9:49

3 Answers 3

24

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.

6
  • 42
    Couldn't they just support docker-compose files? I don't want to rewrite my files just to run them on heroku and nowhere else but heroku.
    – Jens
    Apr 25, 2019 at 15:31
  • 2
    @Jens I hear you. I was wondering the same thing when I read the news. There is probably a reason I am not seeing but it would've made sense to just support docker-compose which is one of the popular options so far. Apr 26, 2019 at 8:03
  • 2
    I wouldn't mind writing a heroku config file if I'm using heroku, but rewriting the whole docker-compose seems too much.
    – Jens
    Apr 27, 2019 at 12:23
  • 6
    Just a heads up, if you are doing some serious amount of compiling in Docker that requires over the 2gb of default memory ie Angular 8+, then it will cryptically fail on heroku. THERE IS NO DOCUMENTATION ON THIS BEHAVIOR and after working with Heroku support, they won't be allowing adjustments to that either.
    – scott
    Jul 24, 2019 at 13:50
  • 3
    @JMillner here's some documentation on heroku.yml, posted 3 days after your question apparently.
    – datu-puti
    May 27, 2020 at 20:39
13

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.
1
  • 7
    Just by way of clarification...I think it is important to stress: Heroku does NOT integrate with docker-compose the way it does with Dockerfiles. Besides the aforementioned environment variables I think starting the app via a 'CMD' statement in the Dockerfile is important as opposed to just assuming that the docker-compose.yml file will do it via the command stanza... ?
    – Travis
    May 29, 2018 at 17:18
0

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.

1
  • 1
    Are you sure that that guide state that it's officially supported? It says you can use docker compose for local development then push a container to Heroku
    – uak
    Jan 10 at 7:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.