Streamlit to work on my Synology NAS

Quite an old thread, but I would like to leave my solution to make Streamlit working on a Docker container on a Synology NAS.

Things to do:

  • Register a DynDNS on your domain register
  • Enable the DynDNS at Synology > Control Panel > External Access > DDNS > …
  • Create a domain certificate, for example, at Let’s Encrypt, going to: Synology > Control Panel > Security > Certificate > Add…
  • Set the certificate for your DynDNS domain, at: Synology > Control Panel > Security > Certificate > Settings …
  • Enable firewall for the Docker container, at Synology > Control Panel > Security > Firewall > Edit Rules > Create > …
  • Setup the reverse proxy, at: Synology > Control Panel > Login Portal > Advanced > Reverse Proxy > …
  • You can enable HSTS if you want at the Reverse Proxy
  • Enable the websocket at: Synology > Control Panel > Login Portal > Advanced > Reverse Proxy > Custom Header > Create > WebSocket > …
  • Setup the Docker container at the “Container Manager” app inside Synology. You can use the docker-compose.yml, and create a “Project”.

As example, these are my files:

Dockerfile

# app/Dockerfile

FROM python:3.12-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install -r requirements.txt

VOLUME ["/app"]

EXPOSE 8501

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

ENTRYPOINT ["streamlit", "run", "main.py", "--server.port=8501", "--server. Address=0.0.0.0"]

docker-compose.yml

version: '3.8'

services:
  streamlit_app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: app
    hostname: app
    ports:
      - 8501:8501
    volumes:
      - type: bind
        source: /volume1/docker/app
        target: /app
    environment:
      - TZ=Europe/London

networks:
  default:
    ipam: 
      driver: default
      config:
        - subnet: "172.1.0.0/16"
          gateway: "172.1.0.1"

Some screenshots of the process:

More information at:

2 Likes