Deploying Docker Containers to Heroku from a Mac M1 Machine

Deploying Docker Containers to Heroku from a Mac M1 Machine

ยท

2 min read

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

  1. Log in to Container Registry:
    heroku container:login
    
  2. Navigate to the application directory and create a Heroku app:
    heroku create <app-name>
    
    Note: Replace <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 name hello-world.herokuapp.com. You will now be able to find hello-world listed on your heroku dashboard.
  3. Build the image: (replace the tag hello-world-tag with your tag)
    docker buildx build --platform linux/amd64 -t hello-world-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 command instead of the normal docker build command since we need to build the image for linux/amd architecture.
  4. Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE. The TARGET_IMAGE here would link the Heroku registry for the app. The SOURCE_IMAGE would be the image tag that we created in Step 3. The syntax of the command is:
    docker tag SOURCE_IMAGE TARGET_IMAGE
    
    In my case, the command would be:
    docker tag hello-world-tag registry.heroku.com/hello-world/web
    
  5. Use docker push to push it to the Heroku container registry:
    docker push registry.heroku.com/hello-world/web
    
  6. Then release the image to your app:
    heroku container:release web -a hello-world
    
  7. Now open the app in your browser:
    heroku open
    

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!

ย