How to deploy Hello world to Heroku using docker

Here is the heroku official doc and steps in this article are my walk through.

Prerequisite: You need to have heroku CLI and docker CLI installed.

Check if you have docker installed properly

Enter docker ps in your terminal and you will see container info if you have installed docker.

>> docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Check if you can login as heroku user

>> heroku login

heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://...
Logging in... done
Logged in as xxx@gmail.com

Login to heroku docker

>> heroku container:login

Login Succeeded

Create an app on heroku

>> heroku create <YOUR_APP_NAME>

Creating app... done, ⬢ <YOUR_APP_NAME>
https://<YOUR_APP_NAME>.herokuapp.com/ | https://git.heroku.com/<YOUR_APP_NAME>.git

You can double check on your heroku account

Clone helloworld to your local

>> git clone https://github.com/heroku/alpinehelloworld.git

Cloning into 'alpinehelloworld'...
remote: Enumerating objects: 59, done.
remote: Total 59 (delta 0), reused 0 (delta 0), pack-reused 59
Unpacking objects: 100% (59/59), done.

Connect you local git to remote heroku git

>> cd alpinehelloworld
>> heroku git:remote -a <YOUR_APP_NAME>

set git remote heroku to https://git.heroku.com/<YOUR_APP_NAME>.git

Build the image and push to Container Registry

>> heroku container:push web

=== Building web (/Users/xx/Documents/GitHub/heroku/alpinehelloworld/Dockerfile)
[+] Building 13.9s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                                                                                  0.1s
 => => transferring dockerfile: 618B                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                     0.0s
 => => transferring context: 46B                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                      0.0s
 => [1/7] FROM docker.io/library/alpine:latest                                                                                        0.0s
 => => resolve docker.io/library/alpine:latest                                                                                        0.0s
 => [internal] load build context                                                                                                     0.0s
 => => transferring context: 791B                                                                                                     0.0s
 => [2/7] RUN apk add --no-cache --update python3 py3-pip bash                                                                        7.7s
 => [3/7] ADD ./webapp/requirements.txt /tmp/requirements.txt                                                                         0.0s
 => [4/7] RUN pip3 install --no-cache-dir -q -r /tmp/requirements.txt                                                                 4.7s
 => [5/7] ADD ./webapp /opt/webapp/                                                                                                   0.0s
 => [6/7] WORKDIR /opt/webapp                                                                                                         0.0s
 => [7/7] RUN adduser -D myuser                                                                                                       0.4s
 => exporting to image                                                                                                                0.7s
 => => exporting layers                                                                                                               0.7s
 => => writing image sha256:xx                                          0.0s
 => => naming to registry.heroku.com/<YOUR_APP_NAME>/web                                                                      0.0s
=== Pushing web (/Users/xx/Documents/GitHub/heroku/alpinehelloworld/Dockerfile)
Using default tag: latest
The push refers to repository [registry.heroku.com/<YOUR_APP_NAME>/web]
8226bf54123c: Pushed
5f70bf18a086: Pushed
1c2b1e95af23: Pushed
db9a34fb2c51: Pushed
18e8c98dbace: Pushed
d963f66aa644: Pushed
1119ff37d4a9: Pushed
latest: digest: sha256:xx size: 1779
Your image has been successfully pushed. You can now release it with the 'container:release' command.

Then release the image to your app

>> heroku container:release web

Releasing images web to <YOUR_APP_NAME>... done

Now open the app in your browser

>> heroku open

Logout heroku container

>> heroku container:logout

Removing login credentials for registry.heroku.com

Last updated