Deploying Docker Containers to Heroku from a Mac M1 Machine
·Dec 20, 2021·
2 min read
Play this article
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.
- Log in to Container Registry:
- Navigate to the application directory and create a Heroku app:
heroku 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-worldwill lead to the domain name
hello-world.herokuapp.com. You will now be able to find
hello-worldlisted on your heroku dashboard.
- Build the image: (replace the tag
hello-world-tagwith 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 the
docker buildx build --platform linux/amd64 -t hello-world-tag .
docker buildxcommand instead of the normal
docker buildcommand since we need to build the image for linux/amd architecture.
- Create a tag
TARGET_IMAGEthat refers to
TARGET_IMAGEhere would link the Heroku registry for the app. The
SOURCE_IMAGEwould 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
docker pushto 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:
Thanks for giving this a read. I hope it helps!
Did you find this article valuable?
Support Saurav Shrivastav by becoming a sponsor. Any amount is appreciated!