Problem deploying streamlit app with Docker

Hi all from France,

I just post my question here because despite all the existing posts on this subject I do not understand the procedure.
For a school project, I use streamlit to build a dashboard, which communicates with a Flask application. I later found that streamlit embeds the Tornado framework directly…

My configuration works well locally, but I have a lot of problems deploying it.

This is what i did :

I built a Docker image with the following files :

  • API.py
  • application_test.csv
  • application_train.csv
  • DASHBOARD.py
  • Dockerfile
  • logo.PNG
  • requirements.txt

dashboard.py is the file containing the streamlit code
api.py is a file containing all the code with Flask. Here Flask works on port 4449

Here is the code of my Dockerfile :

# Python support can be specified down to the minor or micro version
# (e.g. 3.6 or 3.6.3).
# OS Support also exists for jessie & stretch (slim and full).
# See https://hub.docker.com/r/library/python/ for all supported Python
# tags from Docker Hub.
FROM python:3.7.6-slim-buster

# If you prefer miniconda:
#FROM continuumio/miniconda3

LABEL Name=test_azure Version=0.0.1
EXPOSE 4449

# Répeertoire de travail
WORKDIR /app
# Récupération fichiers
COPY . /app

# Using pip:
RUN python3 -m pip install -r requirements.txt
CMD ["python3", "-m", "test_azure"]

# Lance Flask
CMD ["python", "API.py"]

# Lance streamlit
CMD ["streamlit", "run", "DASHBOARD.py"]

Locally, I launch my image and I have a message telling me that streamlit is launched. Unfortunately, nothing appears in my browser at the two proposed URLs.

I am trying to configure the URL in 0.0.0.0 in order to make it public, but I do not understand the procedure.

I have to change the config.toml file but how do I do that?

Could you explain to me how to deploy my application with Docker please?

Thanks,

Regards.

Julien

you’ve to bind ports
you can do it by running something like this

docker run -p 8451:8451 <<image_id_of_container>>

Thank you for your answer.

I managed to deploy my application with a docker on Azure, but I am faced with a new problem, I cannot access (or start) Flask.

Blockquote
ConnectionError: HTTPConnectionPool(host=‘0.0.0.0’, port=5000): Max retries exceeded with url: /init_model (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7f1504a7ecd0>: Failed to establish a new connection: [Errno 111] Connection refused’))

However I think I configured it well in my dockerfile…

...
# Lance Flask
CMD ["python", "API.py"]

# Lance streamlit
ENTRYPOINT ["streamlit", "run"]
CMD ["DASHBOARD.py"]

start flask and streamlit independently

OK, thanks.

I am a beginner with all this. How can I do this please?

Hello @dracfooza,

From the CMD doc, the CMD method is the default command to run when executing a container, so you can’t have multiple CMD lines in your file.

If I recall correctly, you can either :

  • put all your commands in one CMD with : CMD python API.py && streamlit run DASHBOARD.py
  • create a start.sh script with the following lines then : CMD ["./start.sh"]
python API.py
streamlit run DASHBOARD.py
2 Likes

@andfanilo Great !!!

Thanks a lot.