Table of contents
The documentation for deploying docker containers to Heroku is available here. But, building the docker image on a Mac M1 machine is breaking the standard setup ๐. I have put up some steps that one can run to deploy docker containers on Heroku.
Steps
- Log in to Container Registry:
heroku container:login
- Navigate to the application directory and create a Heroku app:
Note: Replaceheroku create <app-name>
<app-name>
with the name you would like to give to your application. In the case of a web app, this name would appear in the domain. For example:heroku create hello-world
will lead to the domain namehello-world.herokuapp.com
. You will now be able to findhello-world
listed on your heroku dashboard. - Build the image: (replace the tag
hello-world-tag
with your tag)
Note: Buildx allows us to build an image for the native architecture, similar to a docker build but it also supports and allows for emulation. We are using thedocker buildx build --platform linux/amd64 -t hello-world-tag .
docker buildx
command instead of the normaldocker build
command since we need to build the image for linux/amd architecture. - Create a tag
TARGET_IMAGE
that refers toSOURCE_IMAGE
. TheTARGET_IMAGE
here would link the Heroku registry for the app. TheSOURCE_IMAGE
would be the image tag that we created in Step 3. The syntax of the command is:
In my case, the command would be:docker tag SOURCE_IMAGE TARGET_IMAGE
docker tag hello-world-tag registry.heroku.com/hello-world/web
- Use
docker push
to push it to the Heroku container registry:docker push registry.heroku.com/hello-world/web
- Then release the image to your app:
heroku container:release web -a hello-world
- Now open the app in your browser:
heroku open
Thanks for giving this a read. I hope it helps!
ย