How do I Access Plotly Dash on a Docker container?

I’ve built my first Docker container but when I run the container either it won’t load or I’m looking in the wrong place. My command line is returning a huge long number without any errors, so I’m assuming I should be able to access the container. However, when I go to http://0.0.0.0:5001/ or http://localhost:5001/ I’m given the error message The site can't be reached

I’m using WSL2 (Ubuntu 20.04) to build the Dash application in Python. I have a Windows 10 machine and I’ve ensured that Docker is set to be compatible with WSL2 and Ubuntu. Below is a copy of my Dockerfile, the code I’ve used to build the container and the code I’ve used to run the container.

When I run the container, it seems to open Python but I’m not too sure what I should be typing into the terminal.

My Docker logs are showing:

Python 3.8.12 (default, Oct 13 2021, 09:15:35)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> docker run
  File "<stdin>", line 1
    docker run
           ^
SyntaxError: invalid syntax
>>> run index.py
  File "<stdin>", line 1
    run index.py
        ^
SyntaxError: invalid syntax
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()

Please can someone explain how I’m supposed to access the Docker container that I’ve built and run? I’m expecting to see the application that I’ve created when I go to either http://0.0.0.0:5001/ or http://localhost:5001/ .

Docker build command: docker build . -t october-2021-challenge-3

Docker run command: docker container run -p 5001:5001 -it --name -stwd-oct-3 october-2021-challenge-3

Dockerfile:

ARG APP_IMAGE=python:3.8

FROM $APP_IMAGE AS base

FROM base as builder


RUN mkdir /install
WORKDIR /install

COPY requirements.txt /requirements.txt

RUN pip install --upgrade pip
RUN python3 -m pip install -r /requirements.txt


FROM base
ENV FLASK_APP index
WORKDIR /project
COPY --from=builder /install /usr/local
ADD . /project

ENTRYPOINT ["python3"]

My requirements file:

Brotli==1.0.9
click==8.0.2
dash==2.0.0
dash-bootstrap-components==0.13.1
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
Flask==2.0.0
Flask-Compress==1.10.1
itsdangerous==2.0.1
Jinja2==3.0.2
MarkupSafe==2.0.1
numpy==1.21.2
pandas==1.3.3
plotly==5.3.1
python-dateutil==2.8.2
pytz==2021.3
six==1.16.0
tenacity==8.0.1
Werkzeug==2.0.2

I’m not a guru in this but I have a similar setup that works. My dockerfile has a CMD command at the end like this:

CMD gunicorn index:server \
--bind 0.0.0.0:8050 \
--timeout 120 \
--workers 3

You need some kind of web server like gunicorn or uwsgi.
In my index.py file I have server = app.server that gets imported from app.py which in theory would contain your app = dash.Dash() call.

Once you get access inside your docker container, Try typing python3 index.py or python index.py i hope this would make your application run inside docker, now you can access the app at the host using the http://0.0.0.0:5001 or http://localhost:5001/ or 127.0.0.1:5001.

This is a general description of a project structure for Dash applications.
There is also a section on “Dockerize our Dash Application” that also uses gunicorn.

You have to install gunicorn: gunicorn · PyPI

Yes thank you! Following this guide helped clear up what I needed to do along with the help of docker-compose logs.

I was not aware this existed, definitely provides some valuable insight. Great find!

I would suggest that you install the following commands first

$ microk8s enable dashboard
$ microk8s enable dns
$ microk8s enable storage
$ microk8s enable registry

That will start up a proxy into the dashboard. The command will give you a URL and login token that you can use to access the dashboard. It results in an output like this:

Checking if Dashboard is running.
Dashboard will be available at https://127.0.0.1:10443
Use the following token to login:
<YOUR LOGIN TOKEN>

I remember working for a chatbot development services provider and I had created a deployment, then I developed the need to author a file that defines it. A simple deployment specification looks like this:

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80