Skip to content

Instantly share code, notes, and snippets.

@capsulecorplab
Last active July 6, 2020 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capsulecorplab/daaee1e7904b3680cd0f6fb6158712f5 to your computer and use it in GitHub Desktop.
Save capsulecorplab/daaee1e7904b3680cd0f6fb6158712f5 to your computer and use it in GitHub Desktop.
"Hello world" app running on Docker Compose. Full tutorial available at https://docs.docker.com/compose/gettingstarted/
# Byte-compiled
__pycache__/
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 Neo! I have been seen {} times.\n'.format(count)
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
environment:
FLASK_ENV: development
redis:
image: "redis:alpine"
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
COPY . .
CMD ["flask", "run"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment