thanks alex, tested in https://labs.play-with-docker.com, it works fine
never thought to combine it with gunicorn and make nginx as a reverse proxy 
(correct me if i'm wrong, still not sure the different with forward proxy 
yet, hehe) and never thought to build some dockerfiles make it into 1 bash 
shell script.
*1. w2p.conf*
cat <<EOF > w2p.conf
upstream gunicorn {
        server  172.25.0.22:9005 fail_timeout=0;
}
server {
    listen        172.25.0.23:80 default_server;
    location / {
        try_files $uri @proxy_to_gunicorn;
    }
    location @proxy_to_gunicorn {
     proxy_set_header X-Real-IP $remote_addr;
     proxy_redirect off;
     proxy_set_header Host $host;
                proxy_pass http://gunicorn;
        }
}
EOF
cat w2p.conf

*2. gunicorn*
cat <<EOF > guniDoc
FROM python:2.7
RUN apt update && apt install -y unzip wget
ENV PATH=/usr/local/bin:$PATH
RUN pip install gunicorn
RUN useradd -m -r  web2py
USER web2py
WORKDIR /home/web2py
RUN  wget -c http://web2py.com/examples/static/web2py_src.zip &&  \
     unzip -o web2py_src.zip && \
     rm -f web2py_src.zip
WORKDIR /home/web2py/web2py
RUN  cp handlers/wsgihandler.py .
CMD /usr/local/bin/gunicorn --workers 4 --timeout=90 --graceful-timeout=10 
--bind :9005 wsgihandler:application
EOF
cat guniDoc

*3. nginx as reverse proxy*
cat <<EOF > nginxDoc
FROM nginx:latest
COPY ./w2p.conf /etc/nginx/conf.d/
RUN apt update
RUN apt-get install curl -y
EXPOSE 80
CMD nginx -g "daemon off;"
EOF
cat nginxDoc

*4. run dockers in shell script*
cat <<EOF > run.sh
docker rm $(docker stop $(docker ps -a -q --filter ancestor=w2pnginx 
--format="{{.ID}}"))
docker rm $(docker stop $(docker ps -a -q --filter ancestor=w2pguni 
--format="{{.ID}}"))
docker network rm w2pnet
#docker network create w2pnet
docker network create --subnet=172.25.0.0/16 w2pnet

docker build -t w2pguni -f guniDoc .
docker run -d --net w2pnet -p 9005:9005 --hostname w2pname  --ip 
172.25.0.22   w2pguni
sleep 2
curl 172.25.0.22

docker build -t w2pnginx -f nginxDoc .
docker run -d --net w2pnet --ip 172.25.0.23  w2pnginx
sleep 2
curl 172.25.0.23

docker ps
EOF
cat run.sh

*5. execute run.sh*
chmod 775 run.sh
./run.sh

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to