Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx/Node/Redis and Flask/Redis Compose example #222

Merged
merged 70 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
59d4fc3
Added Node, Nginx and Redis Project
ajeetraina Mar 5, 2022
22c1733
Added Nginx, Node and Redis project
ajeetraina Mar 5, 2022
3f48871
Added README.md
ajeetraina Mar 5, 2022
fc1b458
Added info instruction
ajeetraina Mar 5, 2022
be66af7
Added info instruction
ajeetraina Mar 5, 2022
81a75f2
Added Info instruction
ajeetraina Mar 5, 2022
dd70b9a
-s
ajeetraina Mar 5, 2022
84109dc
Merge branch 'master' of https://github.com/ajeetraina/awesome-compose
ajeetraina Mar 7, 2022
99d423e
Nginx/Flask/Redis Sample Compose
ajeetraina Mar 7, 2022
6d28165
Added Flask/Redis
ajeetraina Mar 7, 2022
e02b1f4
Flask/Redis
ajeetraina Mar 7, 2022
dc571ec
Flask/Redis
ajeetraina Mar 7, 2022
a780126
Flask/Redis
ajeetraina Mar 7, 2022
6eee259
Flask/Redis
ajeetraina Mar 7, 2022
09b4a23
Updated README.md
ajeetraina Mar 7, 2022
888d42a
Update docker-compose.yml
ajeetraina Mar 7, 2022
5c7d6d7
Update docker-compose.yml
ajeetraina Mar 7, 2022
0a9c252
Added Nginx/node/Redis and Flask/Redis sample apps
ajeetraina Mar 9, 2022
3debcf5
Fixed formatting changes
ajeetraina Mar 12, 2022
e5008d0
Fixed formatting changes
ajeetraina Mar 12, 2022
aed1b15
Fixed formatting changes
ajeetraina Mar 12, 2022
e9e4a51
Merge branch 'docker:master' into master
ajeetraina Mar 13, 2022
aa1d543
Nginx/Node/Redis and Flask/Redis Compose example
ajeetraina Mar 13, 2022
ddd852f
minor changes
ajeetraina Mar 13, 2022
71b6222
modified configuration file for web
ajeetraina Mar 13, 2022
5a53fe5
Update flask-redis/README.md
ajeetraina Mar 13, 2022
d128c1e
Update nginx-nodejs-redis/web/server.js
ajeetraina Mar 13, 2022
9e7d3a5
Update nginx-nodejs-redis/README.md
ajeetraina Mar 13, 2022
ed24220
Restored single service Flask project
ajeetraina Mar 13, 2022
3fec8d0
update versions of eleastic, logstash and kibana with fix of log Log4…
glours Dec 16, 2021
0370339
fix typo (#197)
clach04 Jan 11, 2022
468b963
Added Node, Nginx and Redis Project
ajeetraina Mar 5, 2022
657dc7c
Added Nginx, Node and Redis project
ajeetraina Mar 5, 2022
c14b80b
Added README.md
ajeetraina Mar 5, 2022
8944393
Added info instruction
ajeetraina Mar 5, 2022
944ee4e
Added info instruction
ajeetraina Mar 5, 2022
fcd56cf
Added Info instruction
ajeetraina Mar 5, 2022
5e93fe3
-s
ajeetraina Mar 5, 2022
a062b3a
Nginx/Flask/Redis Sample Compose
ajeetraina Mar 7, 2022
2652caa
Added Flask/Redis
ajeetraina Mar 7, 2022
18e3e53
Flask/Redis
ajeetraina Mar 7, 2022
462087b
Flask/Redis
ajeetraina Mar 7, 2022
183a88a
Flask/Redis
ajeetraina Mar 7, 2022
ba9b73c
Flask/Redis
ajeetraina Mar 7, 2022
47371a1
Updated README.md
ajeetraina Mar 7, 2022
1a354cd
Update docker-compose.yml
ajeetraina Mar 7, 2022
6246391
Update docker-compose.yml
ajeetraina Mar 7, 2022
0614fd5
Added Nginx/node/Redis and Flask/Redis sample apps
ajeetraina Mar 9, 2022
3030c13
Fixed formatting changes
ajeetraina Mar 12, 2022
c285aec
Fixed formatting changes
ajeetraina Mar 12, 2022
75e7bca
Fixed formatting changes
ajeetraina Mar 12, 2022
e880359
fix security issues on react-express-mysql sample
glours Mar 12, 2022
b765dc2
fix security issues on react-express-mongodb sample
glours Mar 12, 2022
83226ff
fix security issues on react-java-mysql sample
glours Mar 12, 2022
e1eef3a
fix security issues on angular sample
glours Mar 12, 2022
a718208
fix security issues on django sample
glours Mar 12, 2022
2aaee7c
fix security issues on react-nginx sample
glours Mar 12, 2022
638af32
fix security issues on vuejs sample
glours Mar 12, 2022
019c555
fix security issues on react-rust-postgres sample
glours Mar 12, 2022
28fd61d
Nginx/Node/Redis and Flask/Redis Compose example
ajeetraina Mar 13, 2022
62bef58
minor changes
ajeetraina Mar 13, 2022
7770fe6
modified configuration file for web
ajeetraina Mar 13, 2022
90dfbd9
Update flask-redis/README.md
ajeetraina Mar 13, 2022
672e115
Update nginx-nodejs-redis/web/server.js
ajeetraina Mar 13, 2022
62a5eca
Update nginx-nodejs-redis/README.md
ajeetraina Mar 13, 2022
1c9841c
Restored single service Flask project
ajeetraina Mar 13, 2022
d9155c4
Merge branch 'master' of https://github.com/ajeetraina/awesome-compose
ajeetraina Mar 13, 2022
60d352e
Update nginx-nodejs-redis/web/Dockerfile
ajeetraina Mar 15, 2022
cbd6bc6
Update flask-redis/Dockerfile
ajeetraina Mar 15, 2022
a8fa3b8
Update nginx-nodejs-redis/web/server.js
ajeetraina Mar 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ a MySQL database.
- [`NGINX / ASP.NET / MySQL`](https://github.com/docker/awesome-compose/tree/master/nginx-aspnet-mysql) - Sample Nginx reverse proxy with an C# backend using ASP.NET
- [`NGINX / Flask / MongoDB`](https://github.com/docker/awesome-compose/tree/master/nginx-flask-mongo) - Sample Python/Flask
application with Nginx proxy and a Mongo database.
- [`NGINX / Flask / MySQL`](https://github.com/docker/awesome-compose/tree/master/nginx-flask-mysql) - Sample Python/Flask
application with an Nginx proxy and a MySQL database.
- [`NGINX / Flask / MySQL`](https://github.com/docker/awesome-compose/tree/master/nginx-flask-mysql) - Sample Python/Flask application with an Nginx proxy and a MySQL database.
- [`NGINX / Node.js / Redis`](https://github.com/docker/awesome-compose/tree/master/nginx-nodejs-redis) - Sample Node.js application with Nginx proxy and a Redis database
- [`NGINX / Go`](https://github.com/docker/awesome-compose/tree/master/nginx-golang) - Sample Nginx proxy with a Go backend.
- [`NGINX / WSGI / Flask`](https://github.com/docker/awesome-compose/tree/master/nginx-wsgi-flask) - Sample Nginx reverse proxy with a Flask backend using WSGI.
- [`PostgreSQL / pgAdmin`](https://github.com/docker/awesome-compose/tree/master/postgresql-pgadmin) - Sample setup for postgreSQL database with pgAdmin web interface
- [`Python / Flask / Redis`](https://github.com/docker/awesome-compose/tree/master/flask-redis) - Sample Python/Flask and a Redis database
- [`React / Spring / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-java-mysql) - Sample React
application with a Spring backend and a MySQL database.
- [`React / Express / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-express-mysql) - Sample React
Expand Down
5 changes: 5 additions & 0 deletions flask-redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.11.0a6-alpine3.15
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py
ajeetraina marked this conversation as resolved.
Show resolved Hide resolved
82 changes: 82 additions & 0 deletions flask-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
## Compose sample application

### Python/Flask application using a Redis database

Project structure:

```
.
├── Dockerfile
├── README.md
├── app.py
├── docker-compose.yml
└── requirements.txt
```

[_docker-compose.yml_](docker-compose.yml)

```
services:
redis:
image: redislabs/redismod
ports:
- '6379:6379'
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
depends_on:
- redis
```

## Deploy with docker-compose

```
$ docker-compose up -d
ajeetraina marked this conversation as resolved.
Show resolved Hide resolved
[+] Running 24/24
⠿ redis Pulled
...
⠿ 565225d89260 Pull complete
[+] Building 12.7s (10/10) FINISHED
=> [internal] load build definition from Dockerfile ...
[+] Running 3/3
⠿ Network flask-redis_default Created
⠿ Container flask-redis-redis-1 Started
⠿ Container flask-redis-web-1 Started
```

## 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
This webpage has been viewed 2 time(s)
```

## 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
```
14 changes: 14 additions & 0 deletions flask-redis/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import Flask
from redis import Redis

app = Flask(__name__)
redis = Redis(host='redis', port=6379)

@app.route('/')
def hello():
redis.incr('hits')
counter = str(redis.get('hits'),'utf-8')
return "This webpage has been viewed "+counter+" time(s)"

if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
13 changes: 13 additions & 0 deletions flask-redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
redis:
image: redislabs/redismod
ports:
- '6379:6379'
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
depends_on:
- redis
2 changes: 2 additions & 0 deletions flask-redis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
redis
108 changes: 108 additions & 0 deletions nginx-nodejs-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
## Compose sample application

## Node.js application with Nginx proxy and Redis database

Project structure:
```
.
├── README.md
├── docker-compose.yml
├── nginx
│   ├── Dockerfile
│   └── nginx.conf
└── web
├── Dockerfile
├── package.json
└── server.js

2 directories, 7 files


```
[_docker-compose.yml_](docker-compose.yml)
```
redis:
image: 'redislabs/redismod'
ports:
- '6379:6379'
web1:
restart: on-failure
build: ./web
hostname: web1
ports:
- '81:5000'
web2:
restart: on-failure
build: ./web
hostname: web2
ports:
- '82:5000'
nginx:
build: ./nginx
ports:
- '80:80'
depends_on:
- web1
- web2
```
The compose file defines an application with four services `redis`, `nginx`, `web1` and `web2`.
When deploying the application, docker-compose maps port 80 of the nginx service container to port 80 of the host as specified in the file.


> ℹ️ **_INFO_**
> Redis runs on port 6379 by default. Make sure port 6379 on the host is not being used by another container, otherwise the port should be changed.

## Deploy with docker-compose

```
$ docker-compose up -d
ajeetraina marked this conversation as resolved.
Show resolved Hide resolved
[+] Running 24/24
⠿ redis Pulled ...
⠿ 565225d89260 Pull complete
[+] Building 2.4s (22/25)
=> [nginx-nodejs-redis_nginx internal] load build definition from Dockerfile ...
[+] Running 5/5
⠿ Network nginx-nodejs-redis_default Created
⠿ Container nginx-nodejs-redis-web2-1 Started
⠿ Container nginx-nodejs-redis-redis-1 Started
⠿ Container nginx-nodejs-redis-web1-1 Started
⠿ Container nginx-nodejs-redis-nginx-1 Started
```


## Expected result

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


```
docker-compose ps
```

## Testing the app

After the application starts, navigate to `http://localhost:80` in your web browser or run:

```
curl localhost:80
curl localhost:80
web1: Total number of visits is: 1
```

```
curl localhost:80
web1: Total number of visits is: 2
```
```
$ curl localhost:80
web2: Total number of visits is: 3
```



## Stop and remove the containers

```
$ docker-compose down
```

27 changes: 27 additions & 0 deletions nginx-nodejs-redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

services:
redis:
image: 'redislabs/redismod'
ports:
- '6379:6379'
web1:
restart: on-failure
build: ./web
hostname: web1
ports:
- '81:5000'
web2:
restart: on-failure
build: ./web
hostname: web2
ports:
- '82:5000'
nginx:
build: ./nginx
ports:
- '80:80'
depends_on:
- web1
- web2


3 changes: 3 additions & 0 deletions nginx-nodejs-redis/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.21.6
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
12 changes: 12 additions & 0 deletions nginx-nodejs-redis/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
upstream loadbalancer {
server web1:5000;
server web2:5000;
}

server {
listen 80;
server_name localhost;
location / {
proxy_pass http://loadbalancer;
}
}
1 change: 1 addition & 0 deletions nginx-nodejs-redis/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions nginx-nodejs-redis/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:14.17.3-alpine3.14

WORKDIR /usr/src/app

COPY ./package.json ./
RUN npm install
ajeetraina marked this conversation as resolved.
Show resolved Hide resolved
COPY ./server.js ./

CMD ["npm","start"]
Loading