From e02b1f4bcafccd297bf2e59704d874e401c5fb44 Mon Sep 17 00:00:00 2001 From: ajeetraina Date: Mon, 7 Mar 2022 11:54:42 +0530 Subject: [PATCH] Flask/Redis --- flask-redis/README.md | 29 ++++++++++++++++++++--------- flask-redis/app/Dockerfile | 7 ------- flask-redis/app/app.py | 9 --------- flask-redis/app/requirements.txt | 1 - flask-redis/docker-compose.yaml | 5 ----- 5 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 flask-redis/app/Dockerfile delete mode 100644 flask-redis/app/app.py delete mode 100644 flask-redis/app/requirements.txt delete mode 100644 flask-redis/docker-compose.yaml diff --git a/flask-redis/README.md b/flask-redis/README.md index b45b948..3a8103c 100644 --- a/flask-redis/README.md +++ b/flask-redis/README.md @@ -25,13 +25,10 @@ services: ``` $ docker-compose up -d -Creating network "flask_default" with the default driver -Building web -Step 1/6 : FROM python:3.7-alpine ... ... -Status: Downloaded newer image for python:3.7-alpine -Creating flask_web_1 ... done +Status: Downloaded newer image for python +Creating flask-redis-web1 ... done ``` @@ -39,17 +36,31 @@ Creating flask_web_1 ... done Listing containers must show one container running and the port mapping as below: ``` -$ docker ps -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -c126411df522 flask_web "python3 app.py" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp flask_web_1 + +$ docker-compose ps +NAME COMMAND SERVICE STATUS PORTS +flask-redis-redis-1 "redis-server --load…" redis running 0.0.0.0:6379->6379/tcp +flask-redis-web-1 "/bin/sh -c 'python …" web running 0.0.0.0:5000->5000/tcp ``` After the application starts, navigate to `http://localhost:5000` in your web browser or run: ``` $ curl localhost:5000 -Hello World! + ``` +## Monitoring Redis keys + +Connect to redis database by using ```redis-cli``` command and monitor the keys. +``` +redis-cli -p 6379 +127.0.0.1:6379> monitor +OK +1646634062.732496 [0 172.21.0.3:33106] "INCRBY" "hits" "1" +1646634062.735669 [0 172.21.0.3:33106] "GET" "hits" +``` + + Stop and remove the containers ``` $ docker-compose down diff --git a/flask-redis/app/Dockerfile b/flask-redis/app/Dockerfile deleted file mode 100644 index cf861e9..0000000 --- a/flask-redis/app/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.7-alpine -WORKDIR /app -COPY requirements.txt /app -RUN pip3 install -r requirements.txt --no-cache-dir -COPY . /app -ENTRYPOINT ["python3"] -CMD ["app.py"] diff --git a/flask-redis/app/app.py b/flask-redis/app/app.py deleted file mode 100644 index e511196..0000000 --- a/flask-redis/app/app.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask import Flask -app = Flask(__name__) - -@app.route('/') -def hello(): - return "Hello World!" - -if __name__ == '__main__': - app.run(host='0.0.0.0') diff --git a/flask-redis/app/requirements.txt b/flask-redis/app/requirements.txt deleted file mode 100644 index 7e10602..0000000 --- a/flask-redis/app/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -flask diff --git a/flask-redis/docker-compose.yaml b/flask-redis/docker-compose.yaml deleted file mode 100644 index 830c446..0000000 --- a/flask-redis/docker-compose.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - web: - build: app - ports: - - '5000:5000'