I would like to deploy my Dash app on Docker. My folder structure:
application
Dockerfile
requirement.txt
index.py
My index.py
if __name__ == '__main__':
app.run_server(host='0.0.0.0', port=8050, debug=True)
My Dockerfile
FROM python:3.7
RUN mkdir /application
WORKDIR /application
COPY requirements.txt /
RUN pip install -r /requirements.txt
COPY ./ ./
EXPOSE 8050
CMD ["python", "./index.py"]
The commands for docker:
docker build -t test_app .
docker run test_app 0.0.0.0:8050 -d
Error: docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused “exec: “0.0.0.0:8050”: executable file not found in $PATH”: unknown.
In deployment, i would recommend using a production grade web server such as gunicorn. Assuming that gunicorn is installed (just add it to the requirement.txt file), you could start it in your docker container like this (here i assume that there is a application file app.py in which the Flask server is called app),
I am not sure what is going wrong in your example. It might be easier to start from a working example to figure it out. As a reference, i have created a MWE where the app is simply,
import dash
import dash_html_components as html
from flask import Flask
server = Flask(__name__)
app = dash.Dash(server=server)
app.layout = html.Div("Hello world.")
if __name__ == '__main__':
app.run_server()
with a corresponding requirements.txt
dash==1.12.0
gunicorn
flask
and a simple Dockerfile,
FROM python:3.8-slim-buster
# Create a working directory.
RUN mkdir wd
WORKDIR wd
# Install Python dependencies.
COPY requirements.txt .
RUN pip3 install -r requirements.txt
# Copy the rest of the codebase into the image
COPY . ./
# Finally, run gunicorn.
CMD [ "gunicorn", "--workers=5", "--threads=1", "-b 0.0.0.0:8000", "app:server"]
You can download the files in the link below along with a docker-compose file for easy deployment.