- in one terminal
git clone $url docker-scaling
cd docker-scaling
docker-compose up --scale flask=5
- in another terminal
for i in `seq 1 200`; do curl localhost:2000; done
**/__pycache__/* |
import socket | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
return "Hello, My container is named: " + socket.gethostname() |
version: '3' | |
services: | |
flask: | |
image: myflask | |
build: | |
context: . | |
dockerfile: Dockerfile.flask | |
volumes: | |
- ./:/src | |
expose: | |
- "5000" | |
environment: | |
- FLASK_APP=/src/app.py | |
nginx: | |
image: mynginx | |
build: | |
context: . | |
dockerfile: Dockerfile.nginx | |
ports: | |
- "2000:80" | |
volumes: | |
- ${PWD}:/var/www-data/ | |
- ./:/etc/nginx/conf.d | |
depends_on: | |
- flask |
FROM python:3 | |
RUN pip3 install flask | |
CMD flask run --host=0.0.0.0 |
# using Nginx base image | |
FROM nginx | |
# delete nginx default .conf file | |
RUN rm /etc/nginx/conf.d/default.conf | |
# add the .conf file we have created | |
COPY nginx.conf /etc/nginx/nginx.conf |
events {} | |
http { | |
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 { | |
listen 80; | |
location / { | |
proxy_pass http://serv; | |
} | |
location /static/ { | |
alias /var/www-data/; | |
} | |
} | |
} |
https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-nginx-on-ubuntu-14-04
simple auth with nginx
Dockerfile
nginx.conf
.htpasswd