mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-19 07:18:06 +02:00
Move all samples to the root dir
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
This commit is contained in:
parent
0c6fcde001
commit
f1e4cca535
262 changed files with 0 additions and 0 deletions
71
nginx-flask-mongo/README.md
Normal file
71
nginx-flask-mongo/README.md
Normal file
|
@ -0,0 +1,71 @@
|
|||
## Compose sample application
|
||||
### Python/Flask application with Nginx proxy and a Mongo database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── docker-compose.yaml
|
||||
├── flask
|
||||
│ ├── Dockerfile
|
||||
│ ├── requirements.txt
|
||||
│ └── server.py
|
||||
└── nginx
|
||||
└── nginx.conf
|
||||
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
services:
|
||||
web:
|
||||
build: app
|
||||
ports:
|
||||
- 80:80
|
||||
backend:
|
||||
build: flask
|
||||
...
|
||||
mongo:
|
||||
image: mongo
|
||||
```
|
||||
The compose file defines an application with three services `web`, `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 80 of the web service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not being used by another container, otherwise the port should be changed.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "nginx-flask-mongo_default" with the default driver
|
||||
Pulling mongo (mongo:)...
|
||||
latest: Pulling from library/mongo
|
||||
423ae2b273f4: Pull complete
|
||||
...
|
||||
...
|
||||
Status: Downloaded newer image for nginx:latest
|
||||
Creating nginx-flask-mongo_mongo_1 ... done
|
||||
Creating nginx-flask-mongo_backend_1 ... done
|
||||
Creating nginx-flask-mongo_web_1 ... done
|
||||
|
||||
```
|
||||
|
||||
## Expected result
|
||||
|
||||
Listing containers must show two containers running and the port mapping as below:
|
||||
```
|
||||
$ docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
a0f4ebe686ff nginx "/bin/bash -c 'envsu…" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp nginx-flask-mongo_web_1
|
||||
dba87a080821 nginx-flask-mongo_backend "./server.py" About a minute ago Up About a minute nginx-flask-mongo_backend_1
|
||||
d7eea5481c77 mongo "docker-entrypoint.s…" About a minute ago Up About a minute 27017/tcp nginx-flask-mongo_mongo_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
Hello fom the MongoDB client!
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
```
|
23
nginx-flask-mongo/docker-compose.yaml
Normal file
23
nginx-flask-mongo/docker-compose.yaml
Normal file
|
@ -0,0 +1,23 @@
|
|||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/tmp/nginx.conf
|
||||
environment:
|
||||
- FLASK_SERVER_ADDR=backend:9091
|
||||
command: /bin/bash -c "envsubst < /tmp/nginx.conf > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
||||
ports:
|
||||
- 8080:80
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
build: flask
|
||||
environment:
|
||||
- FLASK_SERVER_PORT=9091
|
||||
volumes:
|
||||
- ./flask:/src
|
||||
depends_on:
|
||||
- mongo
|
||||
mongo:
|
||||
image: mongo
|
7
nginx-flask-mongo/flask/Dockerfile
Executable file
7
nginx-flask-mongo/flask/Dockerfile
Executable file
|
@ -0,0 +1,7 @@
|
|||
FROM python:3.7
|
||||
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["./server.py"]
|
2
nginx-flask-mongo/flask/requirements.txt
Executable file
2
nginx-flask-mongo/flask/requirements.txt
Executable file
|
@ -0,0 +1,2 @@
|
|||
pymongo
|
||||
flask
|
22
nginx-flask-mongo/flask/server.py
Executable file
22
nginx-flask-mongo/flask/server.py
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
|
||||
from flask import Flask
|
||||
from pymongo import MongoClient
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
client = MongoClient("mongo:27017")
|
||||
|
||||
@app.route('/')
|
||||
def todo():
|
||||
try:
|
||||
client.admin.command('ismaster')
|
||||
except:
|
||||
return "Server not available"
|
||||
return "Hello fom the MongoDB client!\n"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=os.environ.get("FLASK_SERVER_PORT", 9090), debug=True)
|
||||
|
6
nginx-flask-mongo/nginx/nginx.conf
Normal file
6
nginx-flask-mongo/nginx/nginx.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
server {
|
||||
listen 80;
|
||||
location / {
|
||||
proxy_pass http://$FLASK_SERVER_ADDR;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue