# Running dash app in docker container

**URL:** <https://community.plotly.com/t/running-dash-app-in-docker-container/16067>\
**Category:** Dash Python\
**Created:** [November 27, 2018, 4:29pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067 "2018-11-27T16:29:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![blksheephw](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/blksheephw/32/4308_2.png) [@blksheephw](https://community.plotly.com/u/blksheephw)\
**Post date:** [November 27, 2018, 4:29pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/1 "2018-11-27T16:29:27Z")

</div>

Has anyone been able to successfully run a Dash app in a Docker container? I’ve been able to easily run a Flask app but for some reason the same configuration with a Dash app does not work. I’m simply trying to run the Dash app in a container and access it locally but not having any luck 😕

This is my Dockerfile:

```
FROM python:3.6

USER root

WORKDIR /app

ADD . /app

RUN pip install --trusted-host pypi.python.org -r requirements.txt

EXPOSE 80

ENV NAME World

CMD ["python", "app.py"]

```

This is the app (straight from Dash docs but am explicitly using Flask):

```
import dash
import dash_core_components as dcc
import dash_html_components as html
import flask

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

server = flask.Flask( __name__ )
app = dash.Dash( __name__ , server=server,external_stylesheets=external_stylesheets)
app.config.suppress_callback_exceptions = True

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == ' __main__':
    app.run_server(port=8050)

```

Would ultimately like to deploy this to ECS but can’t even get it running locally with `docker run -p 80:80 my_image_name`

Thanks

---

<div class="post-metadata">

**Author:** ![adi](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@adi](https://community.plotly.com/u/adi)\
**Post date:** [November 27, 2018, 7:32pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/2 "2018-11-27T19:32:54Z")

</div>

I’m having the same problem ☹ hopefully someone knows!

---

<div class="post-metadata">

**Author:** ![Philippe](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/philippe/32/3521_2.png) [@Philippe](https://community.plotly.com/u/Philippe)\
**Post date:** [November 27, 2018, 10:40pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/3 "2018-11-27T22:40:17Z")

</div>

You need to expose port 8050 not 80 since that is the port you set when you run the app.

Then  
`docker run -p 8050:8050 my_image_name`

---

<div class="post-metadata">

**Author:** ![tomwire](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@tomwire](https://community.plotly.com/u/tomwire)\
**Post date:** [January 15, 2019, 3:46am UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/4 "2019-01-15T03:46:46Z")

</div>

I got it working in ECS. Edit the app, include the host in the run\_server command

app.run\_server(host=‘0.0.0.0’,debug=True, port=8050)

---

<div class="post-metadata">

**Author:** ![rbcasperson](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/rbcasperson/32/5399_2.png) [@rbcasperson](https://community.plotly.com/u/rbcasperson)\
**Post date:** [January 25, 2019, 8:05pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/5 "2019-01-25T20:05:15Z")

</div>

I was running into this issue as well, and the key for me was to override the default host and using “0.0.0.0”.

Originally I just had `app.run_server()`, and I was unable to access the running container from the browser with the IP and port shown with `docker ps` (or any variation that seemed possible). As soon as I added the host param and used `app.run_server(host=‘0.0.0.0’)` I was able to access the running container from the browser.

---

<div class="post-metadata">

**Author:** ![arpitr07](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@arpitr07](https://community.plotly.com/u/arpitr07)\
**Post date:** [November 29, 2019, 9:56pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/6 "2019-11-29T21:56:23Z")

</div>

Your requirements.txt file for this?

---

<div class="post-metadata">

**Author:** ![datalifenyc](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@datalifenyc](https://community.plotly.com/u/datalifenyc)\
**Post date:** [August 11, 2021, 6:28pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/7 "2021-08-11T18:28:45Z")

</div>

It’s a combination of @Philippe and @tomwire solutions.

- EXPOSE 8050
- Specify host and port in app.py
- If you are actually deploying to cloud service or web, set `debug=False`

The location may not matter, but `EXPOSE <port>` is the last step in my Dockerfile.

The Docker image I use is: continuumio/miniconda3

**References:**  
[How-to Host a Python application with Windows containers on App Service](https://azure.github.io/AppService/2021/03/04/How-to-Host-a-Python-application-with-Windows-Containers-on-App-Service.html)

[Activating a Conda environment in your Dockerfile](https://pythonspeed.com/articles/activate-conda-dockerfile/)

[Connection refused? Docker networking and how it impacts your image](https://pythonspeed.com/articles/docker-connection-refused/)

[YouTube: Deploy a Plotly Dash data visualization app for free on Google Cloud Run in a few simple steps.](https://www.youtube.com/watch?v=1VewIO2Yhmo)

---

<div class="post-metadata">

**Author:** ![Milan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/milan/32/18754_2.png) [@Milan](https://community.plotly.com/u/Milan)\
**Post date:** [September 2, 2022, 4:03pm UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/8 "2022-09-02T16:03:20Z")

</div>

I am having same issue.

Things that does not work for me:

```python
if __name__ == 'main':
    app.run(debug=True, host='127.0.0.1', port=8050)

```

SOLUTION:

```python
if __name__ == 'main':
    app.run(debug=False, host='0.0.0.0', port=8050)

```

Hope this will help!

---

<div class="post-metadata">

**Author:** ![sethugopalan](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@sethugopalan](https://community.plotly.com/u/sethugopalan)\
**Post date:** [September 16, 2023, 4:00am UTC](https://community.plotly.com/t/running-dash-app-in-docker-container/16067/9 "2023-09-16T04:00:28Z")

</div>

I used instead of ADD, COPY app.py /app and changed [http://0.0.0.0:8050](http://0.0.0.0:8050) to [http://localhost:8050](http://localhost:8050) which worked for me
