# How to deploy Hello world to Heroku using docker

Here is the [heroku official doc](https://devcenter.heroku.com/articles/container-registry-and-runtime) and steps in this article are my walk through.

{% hint style="info" %}
Prerequisite: You need to have heroku CLI and docker CLI installed.
{% endhint %}

### 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

![](/files/-MSfvVgdFQHAkxhlVqB7)

### 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://owen31302.gitbook.io/github-education/heroku/how-to-deploy-hello-world-to-heroku-using-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
