✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Running Dash-plotly app with docker results errors

I have a problem during using docker with dash . First:docker installation sample app works very well with me as documentation said.here

Second : what I want is to use docker for a dash-plotly application and then deploy it on aws-beanstack so I followed these steps on this link a link!

Note that I am beginner at docker so pardon for any beginner mistakes .also I have tried many solutions and I dont know where is the problem This is my application.py :

from flask import Flask
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html

server = Flask('main', static_url_path='')

app = dash.Dash(name='main', sharing=True, server=server, url_base_pathname='/main/')
app.layout = html.Div([
    dcc.RadioItems(
        id='ri-1',
        options=[
            {'label': 'A', 'value': 'a'},
            {'label': 'B', 'value': 'b'},
            {'label': 'C', 'value': 'c'}
        ]
    ),
    html.P(),
    html.Div([], className='row', id='ri-val')
])


@server.route('/')
def index():
    return 'another Flask app'


@app.callback(
    Output('ri-val', 'children'),
    [Input('ri-1', 'value')]
)
def ri_cb(ri):
    print ri
    return str(ri)


if __name__ == '__main__':
    server.run(port=8050, host='0.0.0.0', debug=True)

And this is Dockerfile :

FROM amazon/aws-eb-python:3.4.2-onbuild-3.5.1

And this is requirements.txt :

Click==7.0
dash==0.21.1
dash-core-components==0.22.1
dash-html-components==0.10.1
dash-renderer==0.12.1
Flask==0.12.2
Flask-Compress==1.4.0
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
plotly==4.1.1
retrying==1.3.3
six==1.12.0
Werkzeug==0.15.6

Then I use this to run :

amr@amrlinux:~/dash-example$ sudo docker run -it --rm -p 3000:8050 dash-example

the result is this :

*** Starting uWSGI 2.0.8 (64bit) on [Fri Sep 13 14:01:49 2019] ***
compiled with version: 4.9.1 on 04 November 2014 00:03:50
os: Linux-4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019
nodename: 000000000
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /var/app
detected binary path: /var/app/bin/uwsgi
setgid() to 1000
setuid() to 1000

and when I try to navigate http://localhost:3000 it shows that the page is not working Note that when I run the file application.py on the local host :8080 it runs successfully on local host , it doesn’t work with docker . I don’t know where is the problem .

system information : Linux ubuntu 18.1

Not a docker expert myself but a couple of notes to check:

  1. your sudo docker command line indicates the python file is possibly named dash-example.py but later on you mentioned running application.py on local host works ok.
  2. Where is your dash-example.py (or application.py python file located? You may need full path in your sudo docker command.

I run docker run from inside the dash-example file so no need for path, also i tried to use docker without sudo also gives the same results

ok. it seems like the python command to start your application is not running, hence your web page not loading problem. Are you able to start your python app after docker is up? Doing so might show errors.

when I run docker ps
it shows that my image is working well,

CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                    NAMES
xxxxxxxxxxxxx        dash-example             "/uwsgi-start.sh ."   2 minutes ago       Up 2 minutes        0.0.0.0:4000->8080/tcp   wonderful_mcclintock

also I changed 4000 to 3000 the same thing
so I think that the problem is not in the path
so if it is the problem what do you suggest to do?

I figured your docker image is working well. not sure your command to start you python app is though. Within docker, try starting your python app on the command line. if it does not return an error, and you can navigate to your web page, then the problem is in the script that starts docker and attempts to start your python app.

Also, are you trying to navigate to your webpage from a browswer outside of your docker image? thsi could be the problem if you don’t have a route setup (again, not an expert on docker…but worth double-checking)

Maybe this can be of help https://github.com/khannajai/dash-nginx-uwsgi-docker.