Run: docker-compose up --scale flask=12
Created
April 19, 2020 00:09
-
-
Save davidlares/2cfbe55b2d1f8e6e09ad68891d609d00 to your computer and use it in GitHub Desktop.
Scaling Nginx servers via Docker' (a Flask app)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
return "Hello, My container is named: " + socket.gethostname() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
flask: | |
build: . | |
volumes: | |
- ./py:/src | |
environment: | |
- FLASK_APP=/src/app.py | |
nginx: | |
image: nginx:latest | |
ports: | |
- "2000:80" | |
volumes: | |
- ./nginx:/etc/nginx/conf.d | |
depends_on: | |
- flask |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3 | |
RUN pip3 install flask | |
CMD flask run --host=0.0.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream serv { | |
server docker-scaling_flask_1:5000; | |
server docker-scaling_flask_2:5000; | |
server docker-scaling_flask_3:5000; | |
server docker-scaling_flask_4:5000; | |
server docker-scaling_flask_5:5000; | |
server docker-scaling_flask_6:5000; | |
server docker-scaling_flask_7:5000; | |
server docker-scaling_flask_8:5000; | |
server docker-scaling_flask_9:5000; | |
server docker-scaling_flask_10:5000; | |
server docker-scaling_flask_11:5000; | |
server docker-scaling_flask_12:5000; | |
} | |
server { | |
listen: 80; | |
location / { | |
proxy_pass http://serv | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
minimal and to the point! THANK YOU for sharing!
made some little (and likely not so great) updates to make it work after pulling.
https://gist.github.com/pangyuteng/8398773c00204c041dec9dad837aebf4