awesome-compose/flask-redis
2022-03-07 11:54:42 +05:30
..
app.py Added Flask/Redis 2022-03-07 11:45:07 +05:30
docker-compose.yml Added Flask/Redis 2022-03-07 11:45:07 +05:30
Dockerfile Added Flask/Redis 2022-03-07 11:45:07 +05:30
README.md Flask/Redis 2022-03-07 11:54:42 +05:30
requirements.txt Added Flask/Redis 2022-03-07 11:45:07 +05:30

Compose sample application

Python/Flask application

Project structure:

.
├── docker-compose.yaml
├── app
    ├── Dockerfile
    ├── requirements.txt
    └── app.py

docker-compose.yaml

services: 
  web: 
    build: app 
    ports: 
      - '5000:5000'

Deploy with docker-compose

$ docker-compose up -d
...
...
Status: Downloaded newer image for python
Creating flask-redis-web1 ... done

Expected result

Listing containers must show one container running and the port mapping as below:


$ 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

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