Skip to content

Commit

Permalink
Finish docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
rizafahmi committed Nov 22, 2021
1 parent 235d29b commit 77f7294
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]
Binary file added __pycache__/app.cpython-37.pyc
Binary file not shown.
23 changes: 23 additions & 0 deletions app.py
@@ -0,0 +1,23 @@
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 redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)

@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
12 changes: 12 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,12 @@
version: '3.9'
services:
web:
build: .
ports:
- '5000:5000'
volumes:
- '.:/code'
environment:
FLASK_ENV: development
redis:
image: 'redis:alpine'
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
flask
redis

0 comments on commit 77f7294

Please sign in to comment.