web2py gunicorn dockerfile

586 views
Skip to first unread message

黄祥

unread,
Jan 4, 2018, 9:45:04 PM1/4/18
to web2py-users
just wondering why gunicorn dockerfile with web2py/anyserver.py is not work when use with python:2.7 image
e.g.
step i took
cat <<EOF > Dockerfile
FROM python:2.7
RUN apt update && \
 apt install -y unzip wget gunicorn
RUN groupadd -r web2py && \
 useradd -m -r -g web2py web2py
USER web2py
RUN cd /home/web2py/ && \
 unzip -o web2py_src.zip && \
 rm -rf /home/web2py/web2py/applications/examples && \
 chmod 755 -R /home/web2py/web2py
EXPOSE 80
CMD cd ~ && python /home/web2py/web2py/anyserver.py -s gunicorn -i 0.0.0.0 -p 80
EOF
docker build .
docker images
docker run -p 80:80 imageid

result
starting gunicorn on 0.0.0.0:80...
Traceback (most recent call last):
  File "/home/web2py/web2py/anyserver.py", line 365, in <module>
    main()
  File "/home/web2py/web2py/anyserver.py", line 362, in main
    options=options)
  File "/home/web2py/web2py/anyserver.py", line 314, in run
    getattr(Servers, servername)(application, (ip, int(port)), options=options)
  File "/home/web2py/web2py/anyserver.py", line 137, in gunicorn
    from gunicorn.app.base import Application
ImportError: No module named gunicorn.app.base

but it works well when using ubuntu latest image
e.g.
step i took
cat <<EOF > Dockerfile
FROM ubuntu:latest
RUN apt update && \
 apt install -y python python-pip python-setuptools unzip vim wget gunicorn && \
 pip install --upgrade pip && \
 pip install virtualenv && \
 virtualenv /home/site && \
 rm -rf /home/site/web2py && \
 cd /home/site/ && \
 rm -f web2py_src.zip && \
 unzip -o web2py_src.zip && \
 rm -rf /home/site/web2py/applications/examples && \
 chmod 755 -R /home/site/web2py
EXPOSE 80 
CMD . /home/site/bin/activate && /usr/bin/python /home/site/web2py/anyserver.py -s gunicorn -i 0.0.0.0 -p 80
EOF
docker build .
docker images
docker run -p 80:80 imageid


thanks and best regards,
stifan

Alex Beskopilny

unread,
Jan 5, 2018, 10:19:44 AM1/5/18
to web2py-users
Hi
set  WORKDIR in Dockerfile
......
WORKDIR /home/site/web2py
EXPOSE 80
CMD . /home/......
......
docker run 3001:80 image-name

黄祥

unread,
Jan 5, 2018, 5:06:04 PM1/5/18
to web2py-users
trying to modify but got another error 
e.g.
step i took on play-with-docker.com
cat <<EOF > Dockerfile
FROM python:2.7
RUN apt update && \
 apt install -y unzip wget gunicorn
RUN groupadd -r web2py && \
 useradd -m -r -g web2py web2py
USER web2py
RUN cd /home/web2py/ && \
 unzip -o web2py_src.zip && \
 rm -rf /home/web2py/web2py/applications/examples && \
 chmod 755 -R /home/web2py/web2py
WORKDIR /home/web2py/web2py # modified
EXPOSE 80
CMD . /home/web2py/web2py/anyserver.py -s gunicorn -i 0.0.0.0 -p 80 # modified
EOF
docker build .
docker images
docker run -p 3001:80 imageid # same result
docker run -p 80:80 imageid # same result

result
/bin/sh: 10: /home/web2py/web2py/anyserver.py:
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdip...@cs.depaul.edu>

This file is based, although a rewrite, on MIT-licensed code from the Bottle web framework.
: not found
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.

fyi, the python:2.7 dockerfile is work when using default rocket web server (different from above just install the gunicorn package and the cmd to execute the server)
tested to map the port 3001 and 80 from example above got the same result

any idea ?

Alex Beskopilny

unread,
Jan 6, 2018, 12:15:30 PM1/6/18
to web2py-users
1 Dockerfile

FROM centos

RUN yum -y install epel-release && yum clean all
RUN yum -y install python-pip && yum clean all
RUN yum -y update

RUN pip install gunicorn

RUN yum install -y python python-dev
RUN yum install -y git

RUN pip install virtualenv

RUN useradd -ms /bin/bash web2py
USER web2py
RUN git clone --recursive http://github.com/web2py/web2py.git /home/web2py/web2py

EXPOSE 8000

RUN virtualenv  /home/web2py/env

CMD . /home/web2py/env/bin/activate
WORKDIR /home/web2py/web2py
CMD python anyserver.py -s gunicorn -i 0.0.0.0 -p 8000
2  docker build -t w2puser .
docker run -p3001:8000 w2puser
3
curl -I http://localhost:3001
HTTP/1.1 303 SEE OTHER
Server: gunicorn/19.7.1
Date: Sat, 06 Jan 2018 17:05:39 GMT
Connection: close
Content-Type: text/html; charset=UTF-8
Location: /welcome/default/index






On Friday, January 5, 2018 at 5:45:04 AM UTC+3, 黄祥 wrote:

黄祥

unread,
Jan 6, 2018, 7:56:55 PM1/6/18
to web2py-users
yes, it works when using os base image (tested using ubuntu (like in the first post), centos, debian, fedora), the problem occured when using python base image.
the point is when using os base image, it took longer (to install prerequisites package like python curl, git, dll) than using python base image. (tested using web2py source default scaffolding app and rocket)

黄祥

unread,
Jan 6, 2018, 8:10:50 PM1/6/18
to web2py-users
after reread and relearn your dockerfile again it works with some modification with python image (installed gunicorn from pip install not from apt install, and port set into 8000, port 80 not work)
docker run -p 80:80 imageid
[2018-01-07 01:02:10 +0000] [8] [INFO] Starting gunicorn 19.7.1
[2018-01-07 01:02:10 +0000] [8] [ERROR] Retrying in 1 second.
[2018-01-07 01:02:11 +0000] [8] [ERROR] Retrying in 1 second.
[2018-01-07 01:02:12 +0000] [8] [ERROR] Retrying in 1 second.
[2018-01-07 01:02:13 +0000] [8] [ERROR] Retrying in 1 second.
[2018-01-07 01:02:14 +0000] [8] [ERROR] Retrying in 1 second.
starting gunicorn on 0.0.0.0:80...
[2018-01-07 01:02:15 +0000] [8] [ERROR] Can't connect to ('0.0.0.0', 80)

here is the dockerfile that is work with python image
cat <<EOF > Dockerfile
FROM python:2.7
RUN apt update && \
 apt install -y unzip wget python-pip
RUN pip install gunicorn && \
 groupadd -r web2py && \
 useradd -m -r -g web2py web2py
USER web2py
RUN cd /home/web2py/ && \
 unzip -o web2py_src.zip && \
 rm -rf /home/web2py/web2py/applications/examples && \
 chmod 755 -R /home/web2py/web2py
WORKDIR /home/web2py/web2py
EXPOSE 8000
CMD cd ~ && python /home/web2py/web2py/anyserver.py -s gunicorn -i 0.0.0.0 -p 8000
EOF
cat Dockerfile
docker build .
docker images
docker run -p 8000:8000 imageid

Alex Beskopilny

unread,
Jan 6, 2018, 11:22:20 PM1/6/18
to web2py-users

1 Dockerfile

FROM python:2.7
RUN apt update &&  apt install -y unzip wget
RUN /usr/local/bin/pip install gunicorn

RUN groupadd -r web2py &&  useradd -m -r -g web2py web2py
USER web2py
RUN cd /home/web2py/ &&  wget -c http://web2py.com/examples/static/web2py_src.zip &&  unzip -o web2py_src.zip &&  rm -rf /home/web2py/web2py/applications/examples &&  chmod 755 -R /home/web2py/web2py
EXPOSE 8000
WORKDIR /home/web2py/web2py
CMD cd ~ && /usr/local/bin/python /home/web2py/web2py/anyserver.py -s gunicorn -i 0.0.0.0 -p 8000
2
docker build -t w2p33 .
docker run -t w2p33

3
curl -I http://localhost:3001
HTTP/1.1 303 SEE OTHER
Server: gunicorn/19.7.1
Date: Sun, 07 Jan 2018 04:13:58 GMT

Connection: close
Content-Type: text/html; charset=UTF-8
Location: /welcome/default/index

On Friday, January 5, 2018 at 5:45:04 AM UTC+3, 黄祥 wrote:

Alex Beskopilny

unread,
Jan 6, 2018, 11:40:31 PM1/6/18
to web2py-users
small fix
1

FROM python:2.7
RUN apt update && apt install -y unzip wget
RUN /usr/local/bin/pip install gunicorn

RUN groupadd -r web2py &&  useradd -m -r -g web2py web2py
USER web2py
WORKDIR /home/web2py
RUN  wget -c http://web2py.com/examples/static/web2py_src.zip &&  unzip -o web2py_src.zip &&  rm -rf /home/web2py/web2py/applications/examples
EXPOSE 8000
WORKDIR /home/web2py/web2py
CMD /usr/local/bin/python anyserver.py -s gunicorn -i 0.0.0.0 -p 8000

2
 docker build -t w2p33 .
docker run -p3001:8000 -t w2p33

3
curl -I http://localhost:3001
HTTP/1.1 303 SEE OTHER
Server: gunicorn/19.7.1
Date: Sun, 07 Jan 2018 04:37:27 GMT

Connection: close
Content-Type: text/html; charset=UTF-8
Location: /welcome/default/index


On Friday, January 5, 2018 at 5:45:04 AM UTC+3, 黄祥 wrote:

黄祥

unread,
Jan 7, 2018, 8:50:12 AM1/7/18
to web2py-users
is there any dockerfile that contain web2py with nginx ?

黄祥

unread,
Jan 8, 2018, 11:56:09 PM1/8/18
to web2py-users
trying with latest ubuntu and web2py/scripts/setup-web2py-ubuntu.sh return an error
Failed to connect to bus: No such file or directory
step i took
echo '# Emperor uWSGI script

description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
##
#remove the comments in the next section to enable static file compression for the welcome app
#in that case, turn on gzip_static on; on /etc/nginx/nginx.conf
##
#pre-start script
#    python /home/www-data/web2py/web2py.py -S welcome -R scripts/zip_static_files.py
#    chown -R www-data:www-data /home/www-data/web2py/*
#end script
respawn
exec uwsgi --master --die-on-term --emperor /etc/uwsgi --logto /var/log/uwsgi/uwsgi.log
' > uwsgi-emperor.conf
cat uwsgi-emperor.conf

echo '[uwsgi]

socket = /tmp/web2py.socket
pythonpath = /home/www-data/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
uid = www-data
gid = www-data
touch-reload = /home/www-data/web2py/routes.py
cron = 0 0 -1 -1 -1 python /home/www-data/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true
' > web2py.ini
cat web2py.ini

echo '[Unit]
Description = uWSGI Emperor
After = syslog.target

[Service]
ExecStart = /usr/local/bin/uwsgi --ini /etc/uwsgi/web2py.ini
RuntimeDirectory = uwsgi
Restart = always
KillSignal = SIGQUIT
Type = notify
StandardError = syslog
NotifyAccess = all

[Install]
WantedBy = multi-user.target
' > uwsgi.emperor.service
cat uwsgi.emperor.service

echo 'server {
        listen          80;
        server_name     ubuntu;
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /home/www-data/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###

        ###if you use something like myapp = dict(languages=['en', 'it', 'jp'], default_language='en') in your routes.py
        #location ~* ^/(\w+)/(en|it|jp)/static/(.*)$ {
        #    alias /home/www-data/web2py/applications/$1/;
        #    try_files static/$2/$3 static/$3 =404;
        #}
        ###
        
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;

            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section

            ### remove the comments if you use uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
}
server {
        listen 443 default_server ssl;
        server_name     ubuntu;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        keepalive_timeout    70;
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section
            ### remove the comments if you want to enable uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /home/www-data/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###

}' > web2py
cat web2py

cat <<EOF > Dockerfile
FROM ubuntu:latest
RUN apt update && \
 apt -y install sudo curl unzip python-dev python-pip python-setuptools gcc nginx && \
 pip install --upgrade pip uwsgi && \
 mkdir /etc/uwsgi && \
 mkdir /var/log/uwsgi && \
 mkdir /home/www-data && \
 mkdir -p /etc/nginx/ssl/ && \
 ln -s /etc/nginx/sites-available/web2py /etc/nginx/sites-enabled/web2py && \
 rm /etc/nginx/sites-enabled/default && \
 cd /home/www-data/ && \
 unzip -o web2py_src.zip && rm -rf web2py_src.zip && \
 chown -R www-data:www-data web2py && \
 mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py && \
 cd /home/www-data/web2py && \
 sudo -u www-data python -c "from gluon.main import save_password; save_password('password',443)" 
COPY web2py /etc/nginx/sites-available/
COPY uwsgi.emperor.service /etc/systemd/system/
COPY web2py.ini /etc/uwsgi/
COPY uwsgi-emperor.conf /etc/init/
EXPOSE 80
CMD /bin/systemctl restart uwsgi.emperor && /bin/systemctl restart nginx
EOF
cat Dockerfile
docker build .
docker images

docker run -p 80:80 imageid 
Failed to connect to bus: No such file or directory

any idea?

Alex Beskopilny

unread,
Jan 9, 2018, 3:59:26 AM1/9/18
to web2py-users
four files in same directory
1
#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

2
#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;"
3
#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;
        }
}

4
#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
----------------------------
. run.sh
view with firefox http://172.25.0.23



On Friday, January 5, 2018 at 5:45:04 AM UTC+3, 黄祥 wrote:

黄祥

unread,
Jan 9, 2018, 6:41:35 AM1/9/18
to web2py-users
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
     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

Alex Beskopilny

unread,
Jan 9, 2018, 7:16:34 AM1/9/18
to web2py-users
small fix - use dockerDNS
1
# 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 --subnet=172.25.0.0/16 w2pnet

docker build -t w2pguni -f guniDoc .
docker run -d --net w2pnet -p 9005:9005 --name w2pname  --ip 172.25.0.22   w2pguni
# docker exec -it w2pname  bash

sleep 2
ping -c1 -n 172.25.0.22
docker run --net w2pnet busybox ping -c1 -n w2pname
echo "------------------------------------------------------------------"
curl -I 172.25.0.22:9005


docker build -t w2pnginx -f nginxDoc .
docker run -d --net w2pnet --name nginxname --ip 172.25.0.23  w2pnginx
# docker exec -it nginxname  bash

sleep 2
ping -c1 -n 172.25.0.23
docker run --net w2pnet busybox ping -c1 -n nginxname
echo "------------------------------------------------------------------"
curl -I 172.25.0.23

docker ps
docker network ls
docker network inspect w2pnet

2
#w2p.conf
upstream gunicorn {
        server  w2pname:9005 fail_timeout=0;
}

server {
    listen        nginxname:80 default_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;
        }

}



On Friday, January 5, 2018 at 5:45:04 AM UTC+3, 黄祥 wrote:

黄祥

unread,
Jan 9, 2018, 9:19:46 AM1/9/18
to web2py-users
thanks again alex, when executed same like previous tested in https://labs.play-with-docker.com, return an error (acceptable i think because the link and port provided is work (shown web2py welcome apps) )
error traceback
PING 172.25.0.23 (172.25.0.23): 56 data bytes

--- 172.25.0.23 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss
curl: (7) Failed to connect to 172.25.0.23 port 80: Host is unreachable
is it normal or not?

1. w2p.conf
cat <<EOF > w2p.conf
upstream gunicorn {
    #server  172.25.0.22:9005 fail_timeout=0;
    server  w2pname:9005 fail_timeout=0;
}

server {
    #listen        172.25.0.23:80 default_server;
    listen        nginxname: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

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
ping -c1 -n 172.25.0.22
curl 172.25.0.22

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

docker ps
docker network ls
docker network inspect w2pnet

EOF
cat run.sh

黄祥

unread,
Jan 9, 2018, 7:22:19 PM1/9/18
to web2py-users
it works well, my bad, forgot about shell variable is translated when created file using cat

黄祥

unread,
Jan 27, 2018, 8:12:26 AM1/27/18
to web2py-users
want to share the docker stack recipe, if anyone interest perhaps i can pr to the web2py repo or share it on this group
[stack] 
$ ls | grep web2py
web2py-gunicorn-nginx
web2py-rocket-nginx
web2py-rocket-ssl-nginx
web2py-rocket-ssl-nginx-db-adminer
web2py-rocket-ssl-nginx-memcached
web2py-rocket-ssl-nginx-redis
web2py-tornado-nginx

[alpine] 
$ ls | grep web2py
web2py-gunicorn
web2py-rocket
web2py-rocket-ssl
web2py-tornado

note:
- for os base and python base image, better to choose alpine for the size is smallest than any other os base image (tested using centos, debian, fedora, opensuse, ubuntu) and python base image
- in stack there is provided the docker-compose.yml and the run.sh (run docker using shell script run.sh (guided by alec on previous post) )
- everything is tested run well in play-with-docker.com

need improvement for the script (still learning)
- for web2py rocket, hardcode the password to run the rocket server, better to put it as a variable base on user input, but i don't know to do it when using docker compose
- tested web2py-cherrypy ended with error in the anyserver.py is not update the cherrypy library file
- in web2py-rocket-ssl the certificate is build using openssl, which is ended to confirm when using in https (go to unsafe), think better using letsencrypt or something else
- for stack using ldap server, still not found the good image for it, tried to built it from the os base image, ended in configuration of ldap server must be entered by user during setup (setup-ds-admin when using 389-ds and dpkg-reconfigure slapd when using openldap)
- tried to combine stack memcached and redis, not sure if it can be used both (the configuration of the parameter cache and session in web2py)
- tried to build haproxy stack, but not sure the configuration in web2py book is relevant with the haproxy current version

best regards,
stifan

Massimo Di Pierro

unread,
Feb 4, 2018, 12:39:49 AM2/4/18
to web2py-users
Can I ask you to submit a PR to add the dockerfile to the web2py repo?

黄祥

unread,
Feb 4, 2018, 7:08:42 PM2/4/18
to web2py-users
done

best regards,
stifan
Reply all
Reply to author
Forward
0 new messages