How to run a Docker Container in Heroku

Viewed 537

I am writing a Python Django web application which is currently deployed on Heroku. For certain kinds of requests, I want to run a docker container in an isolated environment. For example, one of my API endpoints looks like this:

import docker
def post(request):
    # do some work here...
    client = docker.from_env()
    client.containers.run('some-image', 'some command')
    # format and return response here...

How can I setup my Heroku application so that I can create and run docker containers like this from within my web application? I have tested everything locally and verified that it works. All I need is to deploy this to Heroku.

1 Answers

Update:

I've looked into this some more, and it seems that while the Heroku Platform API does allow you to create one-off dynos on demand, they do not provide complete isolation as each one-off dyno would be injected with the same config vars as the main web process, giving it theoretical access to the database and any other config vars that might be exposed to your application. This behavior has been confirmed by the Heroku support team.

In addition, running an application like this at scale would end up being very expensive on Heroku.

To build an application with this functionality, it looks like the best option is currently to use a different hosting provider.

Related