Last active
July 6, 2020 01:18
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Byte-compiled | |
| __pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3' | |
| services: | |
| web: | |
| build: . | |
| ports: | |
| - "5000:5000" | |
| volumes: | |
| - .:/code | |
| environment: | |
| FLASK_ENV: development | |
| redis: | |
| image: "redis:alpine" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| flask | |
| redis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment