GithubHelp home page GithubHelp logo

sladkovm / docker-flask-gunicorn-nginx Goto Github PK

View Code? Open in Web Editor NEW
167.0 11.0 53.0 514 KB

Bootstrap example of a Flask app served via Gunicorn and Nginx using Docker conteiners

Shell 1.68% Python 92.56% Makefile 1.09% Dockerfile 4.67%
docker flask nginx gunicorn dash plotly-dash

docker-flask-gunicorn-nginx's Introduction

Blueprint for docker-flask-gunicorn-nginx web application

Example App

Bootstrap example of a Flask/Dash app served via Gunicorn and Nginx using Docker containers

Guildeline article can be found at https://sladkovm.github.io/webdev/2017/10/16/Deploying-Plotly-Dash-in-a-Docker-Container-on-Digitital-Ocean.html

Run

make build

In your browser (assuming the docker-machine runs on 192.168.99.100) go to:

http://192.168.99.100

To clean up the container mess, run

make clean

It will shut down all container and remove all images

Prominent features:

  1. Dockerized application orchestrated by docker-compose
  2. Gunicorn as a WSGI and Nginx as a reverse proxy are included as services
  3. Nginx is configured to serve static files, e.g. images, css etc.
  4. Example of routing implementation in Dash app is shown
  5. Build process uses requirements.txt, but Pipenv files are included to ease the development process
  6. Bootstrap css is included
  7. Standard Single Page App Layout with Header, Main and Footer is set up

docker-flask-gunicorn-nginx's People

Contributors

sladkovm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-flask-gunicorn-nginx's Issues

: static_folder is no longer a valid keyword argument in Dash since v1.0.

Hello, this doesn't seem to work anymore. Running the make build command results in this docker error log on the dash_app:

Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/project/dash_app/app.py", line 23, in
csrf_protect=False)
File "/usr/local/lib/python3.6/site-packages/dash/dash.py", line 258, in init
_validate.check_obsolete(obsolete)
File "/usr/local/lib/python3.6/site-packages/dash/_validate.py", line 277, in check_obsolete
key
dash.exceptions.ObsoleteKwargException: static_folder is no longer a valid keyword argument in Dash since v1.0.
See https://dash.plotly.com for details.
[2020-05-17 00:18:44 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-05-17 00:18:44 +0000] [1] [INFO] Shutting down: Master
[2020-05-17 00:18:44 +0000] [1] [INFO] Reason: Worker failed to boot.

Adding a path to root URL

Thanks for this great repo.

I'm having no trouble deploying the dash app using a slightly different nginx configuration. I want to run my dash application on http://example.com/path/, rather than just http://example.com.

To do this, I changed the project.conf file so location / becomes location /path/. Here's what it looks like:

server {

    listen 80;
    server_name docker_flask_gunicorn_nginx;

    location /path/ {
        proxy_pass http://dash_app:8000;

        # Do not change this
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static {
        rewrite ^/static(.*) /$1 break;
        root /static;
    }
}

When I try to run the dash app using this configuration, I get "Error loading layout" in the browser, and looking at the docker logs for the nginx container, I get:

2019/02/11 16:26:20 [error] 6#6: *1 open() "/etc/nginx/html/_dash-layout" failed (2: No such file or directory), client: xxx, server: docker_flask_gunicorn_nginx, request: "GET /_dash-layout HTTP/1.1", host: "example.com", referrer: "http://example.com/path/"
 - - [11/Feb/2019:16:26:20 +0000] "GET /_dash-layout HTTP/1.1" 404 571 "http://example.com/path/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" "-"
2019/02/11 16:26:20 [error] 6#6: *3 open() "/etc/nginx/html/_dash-dependencies" failed (2: No such file or directory), client: xxx, server: docker_flask_gunicorn_nginx, request: "GET /_dash-dependencies HTTP/1.1", host: "example.com", referrer: "http://example.com/path/"

Any idea where I'm going wrong? I'm thinking I'm doing something really simple wrong here but I'm having trouble finding it since I'm not too familiar with nginx.

Thanks!
Mark

why nginx depend on "dash_app"

💡There is one line proxy_pass http://dash_app:8000 in your project.conf

I'm confused how nginx network to dash_app,However,There is no any network declaration in your docker-compose.yml. appreciate for your answer.

502 bad gateway error

Hey!

I ran "bash run_docker". Everything seems to be good, up and running (containers are created, so is the network, etc), but when I navigate to the server IP, I get 502 bad gateway error. Based on docker logs for nginx:

2020/04/20 14:59:27 [error] 8#8: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 37.112.0.151, server: docker_flask_gunicorn_nginx, request: "GET / HTTP/1.1", upstream: "http://172.18.0.2:8000/", host: "139.162.133.232"
37.112.0.151 - - [20/Apr/2020:14:59:27 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" "-"
37.112.0.151 - - [20/Apr/2020:14:59:30 +0000] "GET /favicon.ico HTTP/1.1" 499 0 "http://139.162.133.232/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" "-"

Could you give me a hand with this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.