I was having a similar issue. I was able to solve (at least with a small test app) using streamlit_cookies_controller, Sqlite, in a docker container locally. You can see my test files here. User logged out after page refresh- Need persistent session - #2 by Josh2
I dockerized it by removing the setup_database.py after I already created my database. Then ran a pip freeze > requirements.txt . Then dockerize my 3 files- app.py, requirements.txt, and users.db.
# Use the official lightweight Python image
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app
# Copy the requirements file to the working directory
COPY requirements.txt .
# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code to the working directory
COPY . .
# Expose the port Streamlit runs on
EXPOSE 8501
# Command to run the Streamlit app
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
Build and then Run. It appears to keep state in Chrome from what I’ve tested while running in docker. Maybe it can work for you.