Config.toml not being used in Google Cloud Run

To preface, I don’t know if this is a Streamlit issue, Cloud Run or Docker issue so I’m just asking which ever forums I can to see if I can find an answer.

I’ve built my Streamlit app to run in a container with the following Dockerfile:

FROM python:3.10.12-slim-buster

# Create streamlit_group
RUN groupadd -r streamlit_group

# Create streamlit_user abd add it to the streamlit_group
RUN useradd -r -g streamlit_group streamlit_user

WORKDIR /app

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

COPY requirements.txt .
COPY components components
COPY streamlit_app.py .
COPY .streamlit/config.toml ./.streamlit/config.toml

RUN pip3 install --no-cache-dir -r requirements.txt

RUN chown -R streamlit_user:streamlit_group /app

EXPOSE 8501

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

# Switch to streamlit_user for execution
USER streamlit_user

ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]

When I run the app locally, the config file is picked up and used when viewing the app in a browser. When I inspect the files in the container, it shows the .streamlit/config.toml file so all is good locally.

When I push this to Artifact Registry and then deploy to Cloud Run and view the app, the config file is not loaded and not being used at all. Clicking on the menu in the app to change the theme only shows Light or Dark mode.

If I pull the image from Artifact Registry and run it locally, it shows up. What gives? I’m really not sure what’s causing this and trying to find any leads or solutions. Thanks

1 Like

Hi there @digitalghost-dev !

I suspect the Dockerfile instruction line for copying the .streamlit folder is not correct. Try this instead and let us know how it goes:

COPY .streamlit .streamlit

(Also: to rule out any dependency issues, double-check that the Python and package versions you are running locally match the Docker base image and your requirements.txt file).

Thanks for the response @marduk but that still didn’t seem to work. Same result, works locally but then as soon as it’s deployed, doesn’t apply the config.

I am on a M1 MacBook so when I build the image, I have to build it for linux/amd64 for it be deployed on Cloud Run. Not sure if that is an issue or not…

Might not be because I am also deploying from GitHub using GitHub Actions and the running is the default Ubuntu machine.

Okay, @marduk, I think I found the issue. I went to look at the logs for my Cloud Run service and saw this:

“Could not open file at path /secret_volume_0/config.toml. The path is in a mounted secrets volume, but the exact path does not correspond to any secret specified in the mount configuration.”

I’m assuming the last sentence has something to do with secrets.toml already being mounted to app/.streamlit/ but I’m not sure.

So I figured that I would create another “secret” with the config.toml file contents and mount that has a volume. Well, I can’t do that either because Cloud Run doesn’t allow more than one secret to be mounted in the same path. Here is an issue being tracked on this topic.

So, at this moment, I am stuck and not sure how to solve this. I will consult some other forums that are focused on Google Cloud.

Hey again @digitalghost-dev !

Curious to know if you solved this. Other things you can rule out:

  • Last time I checked, creating Docker images on Macs with ARM64 CPUs… is a source of many headaches. I use GCP Cloud Build instead, so image is built by GCP and added to Artifact Registry when created. Works well.
  • Not sure if this helps but worth a shot. In Cloud Run deployment settings, try the 2nd gen execution environment (file system access).

I assume you already tested with a simple Streamlit app and a simple Dockerfile (only the necessary 3-4 instructions), but try that too if you haven’t.

Hi, @marduk. Yes, I solved this in a different way. I completely removed the config.toml file and in the Dockerfile, I edited the ENTRYPOINT to run the theme configuration for me:

# Dockerfile to build the Streamlit app.

FROM python:3.10.12-slim-buster

RUN groupadd -r streamlit_group

RUN useradd -r -g streamlit_group streamlit_user

WORKDIR /app

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

COPY requirements.txt .
COPY components components
COPY streamlit_app.py .

RUN pip3 install --no-cache-dir -r requirements.txt

RUN chown -R streamlit_user:streamlit_group /app

EXPOSE 8501

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

USER streamlit_user

ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--theme.primaryColor=indigo", "--theme.textColor=black", "--theme.backgroundColor=#FFF", "--theme.secondaryBackgroundColor=#FFF"]
1 Like

create a new config.toml in your current local directory, where the Dockerfile exists and include this line in your Dockerfile

COPY config.toml /usr/local/lib/python3.xx/site-packages/streamlit/config.toml

replace xx with the python version number of your container.