[PYTHON] Launch Flask application with Docker on Heroku

Introduction

About a month ago, leave the Docker image as it is Now that I can deploy it to Heroku, I tried it. It's still in public beta.

reference Container registry public beta - deploy Docker images to Heroku ContainerRegistryandRuntime

Preparation

The following is described assuming that it has already been completed.

Source

I used my own Flask application as the deployment target. https://github.com/nanakenashi/image_clock

It is a simple clock application that switches images according to the time of day.

image_clock/
    ├ static/
    ├ templates/
    ├ Dockerfile
    ├ app.py
    └ requirements.txt
#Use Alpine Linux with Python as base image
FROM python:3.5.2-alpine

#git installation
RUN apk update
RUN apk add git

#Python package installation
ADD requirements.txt /tmp
RUN pip install -r /tmp/requirements.txt

#Place the source code
WORKDIR /web
RUN git clone https://github.com/nanakenashi/image_clock.git clock

#launch flask application
ENV FLASK_APP /web/clock/app.py
CMD flask run -h 0.0.0.0 -p $PORT

The point is the launch of the flask application.

procedure

Prior confirmation

Make sure the docker command is available

$ docker ps

Log in to Heroku.

$ heroku login

Source code placement

Get the source code from GitHub and change to the directory.

$ git clone https://github.com/nanakenashi/image_clock.git ./image_clock
$ cd image_clock

Creating a Heroku application

Secure a place for the application.

$ heroku create flask-clock-sample

At this stage, there is no sauce in it, so it's just a box. When you access it, it looks like this. ↓ Heroku___Welcome_to_your_new_app_.png

Docker container push

Build a container based on the Dockerfile and send it to the repository.

$ heroku container:push --app flask-clock-sample web

Operation check

$ heroku open --app flask-clock-sample

I was able to confirm the operation of the clock application. Clock.png

Summary

Because the application used this time does not use add-ons I was able to set it up and deploy it very simply.

It seems to be a little more difficult to create a Heroku-like configuration such as DB connection and log organization.

Recommended Posts

Launch Flask application with Docker on Heroku
Application development with Docker + Python + Flask
Launch environment with LineBot + Heroku + Docker + Python
Touch Flask + run with Heroku
Output log to console with Flask + Nginx on Docker
Launch Django on a Docker container with docker-compose up
Web application with Python + Flask ② ③
Rails application building with Docker
Web application with Python + Flask ④
(Failure) Deploy a web app made with Flask on heroku
From environment construction to deployment for flask + Heroku with Docker
Creating a Flask server with Docker
Deploy a Django application with Docker
Deploy your Django application on Heroku
Deploy Flask app on heroku (bitterly)
Deploy the Flask app on Heroku
code-server online environment (5) Launch code-server on Docker
Deploy the Flask app on heroku
Build a Flask / Bottle-like web application on AWS Lambda with Chalice
Link WAS and FLASK applications on docker
Write SVG graphs with matplotlib on heroku
Easy web app with Python + Flask + Heroku
Run a Python web application with Docker
Create a web service with Docker + Flask
Getting Started with Heroku, Deploying Flask App
Until you publish (deploy) a web application made with bottle on Heroku
Publish a web application for viewing data created with Streamlit on heroku
How to upload with Heroku, Flask, Python, Git (4)
pykintone on Docker
Redis on Heroku
Vienna with Python + Flask web app on Jenkins
Notes on Flask
shimehari on heroku
Create a bulletin board with Heroku, Flask, SQLAlchemy
Flask application settings
Launch a web server with Python and Flask
A memorandum for touching python Flask on heroku
Until you use PhantomJS with Python on Heroku
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Scraping with Python, posting on TwitterBot, regular execution on Heroku
How to upload with Heroku, Flask, Python, Git (Part 3)
Parse and visualize JSON (Web application ⑤ with Python + Flask)
Set up Docker on Oracle Linux (7.x) with Vagrant
EC2 provisioning with Vagrant + Jupyter (IPython Notebook) on Docker
Memo of deploying Django × Postgresql on Docker to Heroku
Quickly launch Jupyter with Docker (target language: Anaconda / Ruby)
How to upload with Heroku, Flask, Python, Git (Part 2)
Easy build of C ++ code with CMake on Docker
Hobby Web engineer develops web application with Vue.js + Flask (& GCP)
Tftp server with Docker
Install docker on Fedora31
Launch Lambda on Boto3
Use python with docker
IP restrictions with Flask
jsonschema validation on flask
Hello, World with Docker
Install Docker on AWS
Launch code-server on alpine-linux
Hello world with flask
Programming with Python Flask
Install Python 3.6 on Docker