---
title: "Discover How to Leverage Heroku Docker Containers"
description: "Learn how to use the Heroku Docker platform for hosting and running your containers in the cloud with this ATA Learning tutorial!"
canonical: "https://adamtheautomator.com/heroku-docker/"
---

# Discover How to Leverage Heroku Docker Containers

> Learn how to use the Heroku Docker platform for hosting and running your containers in the cloud with this ATA Learning tutorial!

Source: https://adamtheautomator.com/heroku-docker/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Discover How to Leverage Heroku Docker Containers!](https://adamtheautomator.com/wp-content/uploads/2023/02/heroku-docker.jpg)

# Discover How to Leverage Heroku Docker Containers!

[![](https://secure.gravatar.com/avatar/a3e6f24b6b657f0acd2615f1802513a18663dea2e04d24e1df9c1530290e9b48?s=192&d=mm&r=g)Uzma Younas](https://adamtheautomator.com/author/uzma-younas/)14 February 20237 min. read

Categories: [DevOps](/category/devops/)

Tags:[Docker](/tag/docker/)[Heroku](/tag/heroku/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing Heroku CLI](#installing-heroku-cli)
*   [Creating a Heroku Docker Container](#creating-a-heroku-docker-container)
*   [Creating an Application in Heroku](#creating-an-application-in-heroku)
*   [Pushing the Docker Container to Heroku](#pushing-the-docker-container-to-heroku)
*   [Launching the Heroku App](#launching-the-heroku-app)
*   [Conclusion](#conclusion)

Getting tired of worrying about servers instead of focusing solely on writing web applications? Heroku is just the right [Platform as a Service (PaaS)](https://en.wikipedia.org/wiki/Platform_as_a_service) solution for you!

Heroku magically takes care of the building, deploying, running, and scaling process of applications for developers. And in this tutorial, you will create a Heroku Docker which is a Docker container for a Git repository and deploy it on Heroku servers.

Sit back, and relax as you level up your deployment skills with Heroku!

## Prerequisites

This tutorial comprises hands-on demonstrations. To follow along, ensure you have the following in place:

*   A [Heroku](http://www.heroku.com/) account.
    
*   An operating system (OS) supported by Heroku (i.e., macOS, Windows, Linux) – This tutorial uses Windows 11.
    
*   [Git](https://git-scm.com/)’s latest version installed – This tutorial uses version 2.36.1
    

Related:[How to Get Started with Git Bash on Windows](https://adamtheautomator.com/git-bash/)

*   [Docker](https://www.docker.com/) installed.

Related:[How to Install and Use Docker on Ubuntu (In the Real World)](https://adamtheautomator.com/docker-ubuntu/)

## Installing Heroku CLI

Since Heroku applications are managed from the command line, you must install the Heroku CLI, an interface to the [Heroku Platform API](https://devcenter.heroku.com/categories/platform-api).

Although many tasks can be accomplished on Heroku’s website, not everything is available through the dashboard. For complete control over the applications, you need the CLI.

To install Heroku CLI on your system, follow these steps:

1\. Open your favorite web browser, and visit the official [Heroku](https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli) website.

2\. Next, download the specific version for your system, and run the installer, which opens the Heroku setup wizard (step three).

![Downloading Heroku CLI](https://adamtheautomator.com/wp-content/uploads/2023/02/image-99.png)

Downloading Heroku CLI

3\. On the Heroku Setup window, choose the components to install along with Heroku CLI, and click Next.

Make sure to select all components to directly add the path for Heroku in Environment Variables, and let you leverage Heroku commands from the terminal window.

![Choosing components to install](https://adamtheautomator.com/wp-content/uploads/2023/02/image-100.png)

Choosing components to install

4\. Now, keep the default or choose a different install location and click Install to install Heroku CLI.

![Choosing an install location and installing Heroku CLI](https://adamtheautomator.com/wp-content/uploads/2023/02/image-101.png)

Choosing an install location and installing Heroku CLI

5\. Once installed, click Close to finish the installation.

![Finishing the installation](https://adamtheautomator.com/wp-content/uploads/2023/02/image-102.png)

Finishing the installation

6\. When the setup window closes, open your [PowerShell](https://adamtheautomator.com/powershell-run-as-administrator/) or terminal, and run the following command to check Heroku CLI’s installed version.

Related:[Discover How to Run PowerShell as Administrator](https://adamtheautomator.com/powershell-run-as-administrator/)

```xml
 heroku --version
```

Below, you can see the latest version of Heroku CLI as of this writing.

![Verifying Heroku CLI’s installed version](https://adamtheautomator.com/wp-content/uploads/2023/02/image-103.png)

Verifying Heroku CLI’s installed version

7\. Next, run the below command, and press any key to set up a connection with the Heroku website by authentication. A new tab opens in your web browser where you must provide your Heroku credentials.

```xml
heroku login
```

![Setting up a connection with Heroku ](https://adamtheautomator.com/wp-content/uploads/2023/02/image-104.png)

Setting up a connection with Heroku

8\. On the new browser tab, click Log in to authorize your connection to Heroku.

> _Note that you will only need to click Log in, as shown below if you are already logged in to Heroku. Otherwise, you will have to provide your Heroku credentials to log in._

![Authorizing connection to Heroku](https://adamtheautomator.com/wp-content/uploads/2023/02/image-105.png)

Authorizing connection to Heroku

9\. Lastly, close the browser tab, and switch back to your terminal.

![Viewing confirmation of successful login](https://adamtheautomator.com/wp-content/uploads/2023/02/image-106.png)

Viewing confirmation of successful login

Below, you will see the following information regarding a successful connection on your terminal.

![Confirming connection is established with the Heroku service](https://adamtheautomator.com/wp-content/uploads/2023/02/image-107.png)

Confirming connection is established with the Heroku service

## Creating a Heroku Docker Container

With the Heroku CLI installed, you now need a way to encapsulate your application — a Docker container. A Docker container is a lightweight package that includes everything needed to run your application. These containers isolate software from its environment and ensure smooth running regardless of its infrastructure.

As Docker images are reusable and can be deployed on any host, you will be using a Dockerfile to create a Docker image to create a Docker container and deploy it to Heroku.

Related:[Using the Dockerfile ENTRYPOINT and CMD Instructions](https://adamtheautomator.com/dockerfile-entrypoint/)

To create a Docker container, follow these steps:

1\. Run the following [git clone](https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone) command to clone a sample GitHub repository.

This command downloads the source code for the sample app from [GitHub](https://github.com/Adam-the-Automator/HerokuDeployApp.git) to the _HerokuDeployApp_ directory in the working directory.

```powershell
git clone https://github.com/Adam-the-Automator/HerokuDeployApp.git
```

![Cloning a sample GitHub repository](https://adamtheautomator.com/wp-content/uploads/2023/02/image-108.png)

Cloning a sample GitHub repository

> _Git is an essential part of the Heroku platform, and having a basic understanding of how it works is a prerequisite to deploying code to Heroku. Git tracks every source code change, allowing you to revert them quickly. Heroku deployment is “the push” of a local Git repository to a remote provided by Heroku._

2\. Next, navigate to the _HerokuDeployApp_ directory with your file manager or code editor, and view the project structure, as shown below.

The _src_ directory contains all the application code, while the _Dockerfile_ contains the commands to create an image.

![Viewing the project structure](https://adamtheautomator.com/wp-content/uploads/2023/02/image-109.png)

Viewing the project structure

3\. Create a file called _Procfile_ in the project root directory, and add the following line to create a profile (Procfile). Heroku uses a profile that defines each process required to run applications.

The first app represents the name of the Python file launching your application, while the second app represents your (flask) app name.

```powershell
 web: gunicorn app:app 
```

![Adding a profile in the project root directory](https://adamtheautomator.com/wp-content/uploads/2023/02/image-110.png)

Adding a profile in the project root directory

4\. Now, add the [Gunicorn](https://gunicorn.org/) dependency in the _requirements.txt_ file, and save the changes.

Gunicorn is a WSGI web server that runs Python-based web applications concurrently by running multiple Python processes.

![Adding the Gunicorn dependency](https://adamtheautomator.com/wp-content/uploads/2023/02/image-111.png)

Adding the Gunicorn dependency

5\. Create another file called _heroku.yml_ in the project root directory, and add the following line of codes. This file builds Docker images on Heroku and specifies additional configurations to define the Heroku app.

```yaml
build:
  docker:
    web: Dockerfile
```

![Creating a file that builds Docker images on Heroku](https://adamtheautomator.com/wp-content/uploads/2023/02/image-112.png)

Creating a file that builds Docker images on Heroku

6\. Next, change the directory to the project directory, and run the below [docker build](https://docs.docker.com/engine/reference/commandline/build/) command to create a Docker image (heroku-app) to contain your sample application.

```bash
docker build -t heroku-app .
```

![Creating a Docker image for the sample application](https://adamtheautomator.com/wp-content/uploads/2023/02/image-113.png)

Creating a Docker image for the sample application

7\. Once you have a Docker image, run the following [docker run](https://docs.docker.com/engine/reference/commandline/run/) command, which does not produce output but launches your application (heroku-app).

```powershell
docker run -p 5000:5000 -t -i heroku-app:latest
```

8\. Lastly, open a new browser tab, and navigate to [localhost:5000](http://localhost:5000/) to access your application.

If all goes well, you will see the page below confirming your app has been deployed to Heroku.

![Accessing the application running successfully on the localhost ](https://adamtheautomator.com/wp-content/uploads/2023/02/image-114.png)

Accessing the application running successfully on the localhost

## Creating an Application in Heroku

Before deploying a Docker container on Heroku, you must create a Heroku app. Heroku apps are basic organizational units that add new remotes to the Git repository. A remote is located in Heroku servers where code is pushed for deployment purposes.

Run the below `heroku` command to `create` an application. Be sure you replace `<app-name>` with your preferred name, but this tutorial’s choice is heroku-app2725.

```bash
heroku create <app-name>
```

![Creating a Heroku app](https://adamtheautomator.com/wp-content/uploads/2023/02/image-115.png)

Creating a Heroku app

Now, run the following command to add the existing git repository (heroku-app2725) to the remote Heroku repository.

> _GitHub is a contribution and collaboration platform with no hosting option, while Heroku comes with its own servers to host the deployed apps. Adding existing Git repos to Heroku is transferring the Git repo code to Heroku and setting up a running environment for (launching on the server) the application._

```bash
heroku git:remote -a <app-name>
```

![Creating a remote Heroku repository](https://adamtheautomator.com/wp-content/uploads/2023/02/image-116.png)

Creating a remote Heroku repository

## Pushing the Docker Container to Heroku

With the Heroku origin established, you will now push your Docker container to Heroku, where the Heroku server will oversee your app execution. But first, you must ensure that all changes in the repo are committed.

To push your Docker container to Heroku, follow these steps:

1\. Run each git command below to stage (add) and commit the latest changes on your Git repo.

```bash
git add .
git commit -m "First commit to heroku"
```

![Committing the latest changes on the Git repo](https://adamtheautomator.com/wp-content/uploads/2023/02/image-117.png)

Committing the latest changes on the Git repo

2\. Next, run the below command to set your app’s stack to container. A stack is an OS image that offers an application-compatible environment for the application source code on Heroku.

> _Heroku offers different types of stacks to run apps. [Heroku-22](https://devcenter.heroku.com/articles/heroku-22-stack) is currently the default stack for newly developed apps. But for container-based apps, you need to specify it to the [container](https://devcenter.heroku.com/categories/deploying-with-docker)._

Heroku will use your custom Docker container instead of a default [Heroku-curated stack](https://devcenter.heroku.com/articles/stack).

```bash
heroku stack:set container
```

![Setting the application’s stack to ‘container’](https://adamtheautomator.com/wp-content/uploads/2023/02/image-118.png)

Setting the application’s stack to ‘container’

3\. Once the stack is set, run the following command to push your code to Heroku, specifying the heroku remote and Git master branch.

```bash
git push heroku master
```

After pushing, Heroku performs the following:

*   Examines the repository to detect the language and the framework used.
*   Builds a Heroku slug (a copy of your application) ready to be deployed on Heroku’s servers.
*   Removes unnecessary files from Git repository to make the slug as lightweight as possible.

![Pushing the Git repository to Heroku servers](https://adamtheautomator.com/wp-content/uploads/2023/02/image-119.png)

Pushing the Git repository to Heroku servers

4\. Now, run the below heroku command to scale the [Heroku Dyno](https://www.heroku.com/dynos) for your web app. Dynos are lightweight Linux containers dedicated to running application processes.

Since you are deploying a web application, you will use Web Dynos (web=1) to handle web processes.

```bash
heroku ps:scale web=1
```

![Scaling Heroku Dyno for the web app](https://adamtheautomator.com/wp-content/uploads/2023/02/image-120.png)

Scaling Heroku Dyno for the web app

5\. Lastly, visit the Heroku [dashboard](https://dashboard.heroku.com/apps), and you can see your app listed, as shown below.

![Viewing the Heroku app from the dashboard](https://adamtheautomator.com/wp-content/uploads/2023/02/image-121.png)

Viewing the Heroku app from the dashboard

## Launching the Heroku App

Now the app is ready to use. After setting up a running web server for your Heroku app, it is time to launch it and test if it works.

Open a new web browser tab, and navigate to your Heroku app (i.e., _https://<heroku-app-name>.herokuapp.com_), where `<heroku-app-name>` is your app’s name.

By default, all Heroku applications have a domain name format of _[applicationname.herokuapp.com](http://applicationname.herokuapp.com)_. This domain directs requests to the web server.

Alternatively, head back to the Heroku [dashboard](https://dashboard.heroku.com/apps), access your app’s overview page, and click **Open app** (upper-right) to access your web app.

![Launching the web app from the Heroku dashboard](https://adamtheautomator.com/wp-content/uploads/2023/02/image-122.png)

Launching the web app from the Heroku dashboard

If everything works correctly, your browser redirects to your deployed web app, as shown below.

![Confirming the Heroku server runs the web app](https://adamtheautomator.com/wp-content/uploads/2023/02/image-123.png)

Confirming the Heroku server runs the web app

> _If the application fails to serve a user’s request, click the More dropdown (upper-right) and select View logs to know as much information as possible about the failure. Heroku maintains detailed information about each error in its logs._

![Viewing Heroku application logs](https://adamtheautomator.com/wp-content/uploads/2023/02/image-124.png)

Viewing Heroku application logs

## Conclusion

In this tutorial, you have gone through the process of deploying Docker containers to the Heroku platform for execution. Heroku creates a new release and restarts the application automatically when you push new code or modify resources.

Why not try another on-demand development model? The “[develop and deploy](https://towardsdatascience.com/deploying-a-web-app-using-heroku-google-cloud-github-1661379fb1b5) on the cloud” model lets the developers use a browser-based integrated development environment (IDE) to write and build code.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fheroku-docker%2F&text=Discover%20How%20to%20Leverage%20Heroku%20Docker%20Containers!)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fheroku-docker%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fheroku-docker%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-13.webp)

### [Azure Container Apps: Instant Preview Environments per PR](/build-ephemeral-preview-environments-every-pr/)

Build isolated preview environments for every pull request using Azure Container Apps revision labels and Azure DevOps pipelines with scale-to-zero economics.

![](https://adamtheautomator.com/wp-content/uploads/2025/11/55418e927e511ae263219c072e27d637c2a967a5036de7020b329582db775c26.png)

### [Automating Docker Container Health Checks with Python and Local Notifications](/docker-health-checks-python/)

Docker's built-in health checks are passive—they tell Docker when a container fails, but do they tell you? In this tutorial, we'll build a lightweight Python monitoring system that runs entirely on your infrastructure with zero external dependencies. You'll learn to detect container failures in real-time, send instant alerts, and maintain a complete audit log of every state change.

![](https://adamtheautomator.com/wp-content/uploads/2023/07/gitea-docker.jpg)

### [Gitea Docker: Your Ultimate Self-Hosted Git Solution](/gitea-docker/)

Learn how to install a Gitea Docker instance and self-host Git repositories securely in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
