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

前端 未结 2 508
独厮守ぢ
独厮守ぢ 2020-12-13 18:57

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 m

相关标签:
2条回答
  • 2020-12-13 19:43

    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.
    0 讨论(0)
  • 2020-12-13 19:45

    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.

    0 讨论(0)
提交回复
热议问题