create a web2py docker image and access it through browser
Asked Answered
E

2

6

I'm trying to build a docker image of web2py on top of ubuntu. Given the docker file

    #######################
    # Web2py installation #
    #######################

    # Set the base image for this installation
    FROM ubuntu

    # File Author/ Mainteainer
    MAINTAINER sandilya28

    #Update the repository sources list
    RUN apt-get update --assume-yes

    ########### BEGIN INSTALLATION #############

    ## Install Git first
    RUN apt-get install git-core --assume-yes && \ 
    cd /home/ && \ 
    git clone --recursive https://github.com/web2py/web2py.git

    ## Install Python

   RUN sudo apt-get install python --assume-yes

   ########## END INSTALLATION ################

   # Expose the default port
   EXPOSE 8000

   WORKDIR /home/

By building an image using the above Dockerfile

docker build -t sandilya28/web2py .

Then by building a container using the above image

docker run --name my_web2py -p 8000:8000 -it sandilya28/web2py bash

The ip address of the host is

192.168.59.103

which can be found by using boot2docker ip

After creating the image I'm starting the web2py sever using

python web2py/web2py.py

and I'm trying to access the web2py GUI from 192.168.59.103:8000 but it is showing the page is not available.

How to access the GUI of web2py from the browser.

Edelman answered 25/5, 2015 at 7:11 Comment(7)
0 down vote I build your container, but when I log in with your command, and then laucnch web2py.py, I get WARNING:web2py:GUI not available because Tk library is not installed choose a password: please visit: http://127.0.0.1:8000/ use "kill -SIGTERM 16" to shutdown the web2py server so I guess something is wrong with python2/python3 and the tk libraryAirplane
as the container doesn't have any GUI , I think this won't matterEdelman
how do you start nginx and uwsgi?Porosity
You should start web2py that way : python web2py.py -a 'your password' -i 127.0.0.1 -p 8000 ; Which should avoid the start of the GUI widget asking to provide administrator password and other parameters.Jackson
Related documentation about command line options for launching web2py instance : web2py.com/books/default/chapter/29/04/…Jackson
You should use the parameter '-i 0.0.0.0' so that web2py will listen on all active interface. By default, it listen only on the local interface (127.0.0.1), which is not available on other devices on the network (you can consider your host and the container as devices on a network).Dorkas
Can you review my answer?Parke
P
1

Creating a docker that runs the development webserver will leave you with a very slow solution as the webserver is single threaded and will also serve all static files. It's meant for development.

As you don't use https it will also disable the web2py admin interface: that's only available over http if you access it from localhost.

That being said, you can get your solution up and running by starting web2py with:

python web2py.py --nogui -a admin -i 0.0.0.0

All options are important as web2py needs to start the server without asking any questions and it needs to bind to external netwerk interface address.

When you want to use a production ready docker to run web2py you would need some additional components in your docker; nginx, uwsgi and supervisord would make it a lot faster and give you the options to enable https. Note: for bigger projects you would probably need python binding for MySql or PostgreSQL and a separate docker with the database.

An production example, without fancy DB support, can be found here:

https://github.com/acidjunk/docker-web2py

It can be installed from the docker hub with:

docker pulll acidjunk/web2py

Make sure to read the instructions as you'll need a web2py app; that will be mounted in the container. If you just want to start a web2py server to fiddle around with the example or welcome app you can use:

docker pull thehipbot/web2py

Start it with:

docker run -p 443:443 -p 80:80 thehipbot/web2py

Then fire up a browser to

https://192.168.59.103

Parke answered 10/2, 2017 at 20:52 Comment(0)
S
0

Look at the example app I created on github:

Main features:

  • Stripped down version of the base w2p app
  • Dev mode friendly (admin console)
  • Served by Gunicorn (optimized for use in Docker containers)
  • Naked URL i.e. http://localhost:8080, no extra URL paths
  • Dockerfile + k8s

Hope this helps.

Schwejda answered 20/11, 2019 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.