Dash on Jupyter hosted in Docker

Hello,
I have a question similar to old unanswered question from 2021

I am having some hard times getting Dash to run properly in Jupyter (hosted on my local machine in a docker env).

I finally got it to run when biding on 0.0.0.0 such as this:

from dash import Dash, html

app = Dash(__name__)

app.layout = html.Div("Hello!")

if __name__ == "__main__":
    app.run(host='0.0.0.0', jupyter_mode="tab", port=6010)

However this returns:
Dash app running on http://0.0.0.0:6010/

And thus “breaks” jupyter interaction as it tries to load 0.0.0.0:6010, since i am accessing it from outside docker it should be on 127.0.0.1 since i mapped the ports.
I have to go and change it to 127.0.0.1 manually each time which doesn’t make for a good experience (and this only works when using the new tab mode “tab”, any other mode such as “inline” etc. will just break).

I tried using
proxy='http://0.0.0.0:6010::http://127.0.0.1:6010'

But this still returns the 0.0.0.0 binding.

Since it is in docker, if i set 127.0.0.1 as the host the connection is simply declined, since it is initialized outside of docker, from my localhost.

Is there any way to uses 0.0.0.0 binding while having it return the proxy address ?
Or is there any Flask parameters i am not aware off ?
Or even docker settings other than exposing/mapping the ports ?

Thanks.

So i have figured out a “partial” workaround if ever any one has the same issue.

On windows i installed a “loopback interface network adapter” on which i set a manual ip matching the container one (172.20.0.2).
This allow my station to have a local route with the same ip, so connecting to itself (same as 127.0.0.1)

And i run the app with:

app.run(host='172.20.0.2', jupyter_mode="tab", port=7860)

This at least lets the “tab” mode work (not requiring to edit the ip by hand every time) as the container it ok using it’s docker ip, jupyter will return that ip, and my computer will connect to itself through that dummy interface.

For linux you could have a look at “iptables”

I would still love to get a clean solution rather than that ugly work around, and this doesn’t seem to work for “inline” mode

1 Like