Search code examples
javadockerherokucloudheroku-postgres

Is there a way to deploy two containers in one heroku app?


Is there any way to deploy two containers in just one app on heroku?

I have this question because I need to upload two Java applications to heroku, where I have a database configured in an app. These two applications, an API and a database update process need to access the same database.

If there is no way to upload two containers on heroku to solve this case, how would you do it? Having to upload a remote database, a process that updates that database based on a cron job and shell script and an API that accesses the updated database?

Would it be an option to have a single image with both applications and jobs?


Solution

  • It is possible to expose only one port on a Web Dyno therefore it is not possible to deploy 2 applications together if both require HTTP connectivity.

    Option Web and Worker Dynos

    The API processes the HTTP incoming traffic while the backend (DB) app runs in the background as worker: they communicate via a queue, for example RabbitQM, or you can use Redis (same concept: one app produces, the other consumes)

    Option 2 Web Dynos

    Deploy the 2 apps independently on 2 different web Dynos, then communicate over HTTPS using a secure token.

    Option both apps in one Docker image

    Although it is technically possible you won't find around much help (and consent) about it as it violates the Docker principles.

    If you really want to give it a try I think you can start both apps (on different ports) and expose only the API one for incoming traffic.