Saturday, May 25, 2019

Flask and Docker

I wanted to improve the portability of the Physics Derivation Graph, and I recognized the value of putting the code in a Docker image. As a Docker image, anyone would be able to get started with editing and contributing quickly rather than resolving software dependencies.

In addition to improving portability, I also recognize a command-line interface is not sufficient for most users. With the code in a Docker image, another useful change would be to run a webserver in the container. The web server could both display the current state and be the interface for making edits to the content.

I have heard of nginx but not used it. Another option is lighttpd; I haven't used that either. While either of these two options would be sufficient for running static HTML content or something interactive (eg PHP or cgi), my backend code is currently Python. Therefore, I think Flask is a reasonable choice for presenting a web interface and enabling edits to the database.

Update 20200512: good explanation of the relevance of Nginx: https://rushter.com/blog/gunicorn-and-low-and-slow-attacks/

Update 20190602:

cd to your local copy of
https://github.com/allofphysicsgraph/proofofconcept/tree/gh-pages/sandbox/docker_images/flask_ubuntu
docker build -t flask_ub:latest .
To run interactively and manually, use
docker run -it --publish 5000:5000 --mount type=bind,source="$(pwd)",target=/another --entrypoint /bin/bash flask_ub
and then run
python3 app/controller.py
inside the Docker container.  To run interactively automatically, use
docker run -it --publish 5000:5000 flask_ub
In either case, navigate your browser to http://localhost:5000 to use the interface.

No comments:

Post a Comment