featurepreneur
Published in

featurepreneur

How to Deploy Docker Container on Heroku? | Part - 2

In the previous article, we’ve seen about How to Deploy a Flask app on Heroku. If you haven’t seen it yet, click the below link to see it.

Structure of Folder -

app/
app.py
requirements.txt
Dockerfile
docker-compose.yml
  1. Create a New Folder, Go inside it. Initialize it as Git Repository.
mkdir your-folder-name
cd your-folder-name
git init

2. Create a Simple Hello World Flask Application

app.py

from flask import Flask
from os import environ
app = Flask(__name__)@app.route('/')
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(debug = True, host = '0.0.0.0', port=environ.get("PORT", 5000))

3. Add the libraries which you have used in this Application in requirements.txt

requirements.txt

flask

4. Create a Dockerfile to dockerize the Flask Application

Dockerfile

FROM python:3.8-alpineWORKDIR /appADD . /appRUN pip install -r requirements.txtCMD ["python", "app.py"]EXPOSE 5000

5. Create a docker-compose.yml file

docker-compose.yml

version: '2'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/app

6. Run locally by using the below command and check whether it is working or not

sudo docker-compose up

Press Ctrl + C to stop the running container.

7. Login into your Heroku and Docker account

heroku loginsudo docker login --username=<username> --password=<password>

8. Login into Heroku Container

sudo heroku container:login

9. Create a new Heroku app and add the Existing local directory to Remote Heroku Repository

heroku create <app-name>heroku git:remote -a <app-name>

10. Push and Release

sudo heroku container:push web --app <app-name>sudo heroku container:release web --app <app-name>

Open browser and Enter the URL https://<app-name>.herokuapp.com/

You can see the output Hello World! in the browser.

Thank you for reading this article.

--

--

--

Microprediction/Analytics for Everyone! We help volunteers to do analytics/prediction on any data!

Recommended from Medium

The character of Kotlin

Four principles for software engineering

How can WardenSwap find the best rate? 💪

Molot Vst Free Download

How to configure a mail server with a Digital Ocean droplet in 2021

Getting Started with TDD in AWS

📨 Kick Ecosystem presents you an MVP version of KickMessenger

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hari Prasad

Hari Prasad

More from Medium

Simple REST API application using Flask

Deploying Flask Application on Heroku

Sending Text Messages via Twilio/Python

Fun Personality check with REST API in 7 minutes.