Deploying an existing Docker image to Heroku
Got a Docker image you want to deploy as-is on Heroku? Heroku’s documentation doesn’t mention it is possible, while Stack Overflow provides an -old- partial answer. But deploying a Docker image published on the Docker registry directly to Heroku is possible. You’ll still need to get some work done on your machine, using the Heroku and Docker CLIs.
Pulling the image
The first step is to pull the image from the Docker registry (let’s call it my/image
) and find its ID ( image_id
):
docker pull my/image
docker images | grep my/image | awk '{print $3}'
Pushing to Heroku
Providing you’re already logged into Heroku (via heroku login
), you’ll then need to tag and push the image to your Heroku application (let’s call it my-heroku-app
):
docker tag image_id registry.heroku.com/my-heroku-app/web
docker push registry.heroku.com/my-heroku-app/web
Deploying!
Finally, to actually deploy the image:
heroku container:release web --app=my-heroku-app
Automatizing
It is possible to fully automate the process in a script. I published a Github gist to do just that as a proof of concept. Such script could obviously be improved (passing the Docker image and Heroku app as parameters, etc.), but it gets the job done: