Streamlit on Alpine

Ok i’m writing this because i spent too much time trying to deploy a Streamlit app containerized on Alpine (security guys go brrr) and damn it was hard. But i somehow managed to run the server, so maybe this is no the solution but ate least a step forward.
Here is my Dockerfile:

FROM alpine:3.19.1

RUN apk update && apk add \
    py3-pip \
    py3-pyarrow \
    && rm -rf /var/lib/apt/lists/*

COPY . /app
WORKDIR /app

RUN pip3 install --break-system-packages -r requirements.txt

CMD ["streamlit", "run", "Inicio.py", "--server.port=8501", "--server.address=0.0.0.0"]

Some notes:

  1. The ‘–break-system-packages’ is not me trying to sabotage you. It’s just that pip don’t want to run into systemwide packages and break everything. But as we are on Docker, this is not a threat (well, at least not in my case).
  2. Py3-pyarrow: The saviour. Without this, we would have to build pyarrow from source. This includes putting g++ and gcc in ‘apk add’.

Again, this may not be the final solution, but after hopping through many Stackoverflow posts and trying to recreate the entire Linux Kernel i finally managed to “You can now view your Streamlit app in your browser.”.

3 Likes