Member-only story

Deploy basic Python web application with Docker Compose

Meghasharmaa
6 min readApr 28, 2024

Using the Flask framework, the application features a hit counter in Redis, providing a practical example of how Docker Compose can be applied in web development scenarios.

👉Prerequisites:

  • Ensure Docker is installed on your machine. Docker allows you to package your application and its dependencies into a container.
  • Installed the latest version of Docker Compose
  • A basic understanding of Docker concepts and how Docker works
  • You should have Python installed to run the Flask application locally and manage Python dependencies.
  • Use a text editor or an Integrated Development Environment (IDE) to write your Python code. Popular choices include Visual Studio Code, PyCharm or Sublime Text.

👉Set Up Project :

First, create a directory for your project and navigate into it.

$ mkdir flask-redis-app

$ cd flask-redis-app

Create a file called app.py in your project directory.

import time

import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)

def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except…

--

--

Meghasharmaa
Meghasharmaa

Written by Meghasharmaa

DevOps Architect | AWS | Docker | Kubernetes | Terraform | Google Cloud | Python

No responses yet