Created
August 21, 2018 14:14
-
-
Save redknitin/d25dcbc71e4562d4aaed4f0b51ef9b6f to your computer and use it in GitHub Desktop.
Docker example
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 flask import Flask | |
| from redis import Redis, RedisError | |
| import os | |
| import socket | |
| redis = Redis(host='redis', db=0, socket_connect_timeout=2, socket_timeout=2) | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def hello(): | |
| try: | |
| visits = redis.incr("cnt") | |
| except RedisError: | |
| visits = "<i>Redis Error</i>" | |
| html = "<h3>Hello {name}!</h3> <b>Hostname: {hostname}</b><br/> Visits: <i>{visits}</i>" | |
| return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits) | |
| if __name__=='__main__': | |
| app.run(host='0.0.0.0', port=80) | |
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: . | |
| # image: friendlyhello #Create image as docker build -t friendlyhello . | |
| ports: | |
| - "4000:80" | |
| links: | |
| - redis | |
| redis: | |
| image: redis | |
| volumes: | |
| - "/Users/mabit/Documents/Nitin/NitinSandbox/dockery/pything01/data:/data" | |
| command: redis-server --appendonly yes | |
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: | |
| image: friendlyhello | |
| deploy: | |
| replicas: 1 | |
| restart_policy: | |
| condition: on-failure | |
| resources: | |
| limits: | |
| cpus: "0.5" | |
| memory: 50M | |
| ports: | |
| - "4000:80" | |
| networks: | |
| - webnet | |
| redis: | |
| image: redis | |
| ports: | |
| - "6379:6379" | |
| volumes: | |
| - "/Users/mabit/Documents/Nitin/NitinSandbox/dockery/pything01/data:/data" | |
| deploy: | |
| placement: | |
| constraints: [node.role==manager] | |
| command: redis-server --appendonly yes | |
| networks: | |
| - webnet | |
| networks: | |
| webnet: | |
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:2.7-slim | |
| WORKDIR /app | |
| ADD . /app | |
| RUN pip install --trusted-host pypi.python.org -r requirements.txt | |
| EXPOSE 80 | |
| ENV NAME World | |
| CMD [ "python", "app.py" ] |
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