1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-26 10:43:35 +02:00

Added Flask/Redis

Signed-off-by: ajeetraina <ajeetraina@gmail.com>
This commit is contained in:
ajeetraina 2022-03-07 11:45:07 +05:30
parent 99d423e7dd
commit 6d2816541c
17 changed files with 36 additions and 85 deletions

5
flask-redis/Dockerfile Normal file
View file

@ -0,0 +1,5 @@
FROM python
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py

56
flask-redis/README.md Normal file
View file

@ -0,0 +1,56 @@
## Compose sample application
### Python/Flask application
Project structure:
```
.
├── docker-compose.yaml
├── app
   ├── Dockerfile
   ├── requirements.txt
   └── app.py
```
[_docker-compose.yaml_](docker-compose.yaml)
```
services:
web:
build: app
ports:
- '5000:5000'
```
## Deploy with docker-compose
```
$ 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
```
## Expected result
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
```
After the application starts, navigate to `http://localhost:5000` in your web browser or run:
```
$ curl localhost:5000
Hello World!
```
Stop and remove the containers
```
$ docker-compose down
```

15
flask-redis/app.py Normal file
View file

@ -0,0 +1,15 @@
# compose_flask/app.py
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
redis.incr('hits')
return 'This webpage has been viewed %s time(s).' % redis.get('hits')
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)

View file

@ -0,0 +1,7 @@
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"]

9
flask-redis/app/app.py Normal file
View file

@ -0,0 +1,9 @@
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(host='0.0.0.0')

View file

@ -0,0 +1 @@
flask

View file

@ -0,0 +1,5 @@
services:
web:
build: app
ports:
- '5000:5000'

View file

@ -0,0 +1,14 @@
version: '2'
services:
redis:
image: redislabs/redismod
ports:
- '6379:6379'
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
depends_on:
- redis

View file

@ -0,0 +1,2 @@
flask
redis