My streamlit app containerized with Docker (following the streamlit tutorial here) runs fine locally but has the following error when deployed to Google Cloud Run:
FileNotFoundError: No secrets files found. Valid paths for a secrets.toml file are: /home/app/.streamlit/secrets.toml, /home/app/.streamlit/secrets.toml
Steps to reproduce
Deploy any streamlit app with a secrets.toml file to Google Cloud Run.
Expected behavior:
/.streamlit/secrets.toml is deployed with the Docker image since I placed the code:
COPY . /home/app
within the Dockerfile, which should copy all the content of the app (including /.streamlit/secrets.toml) on the Docker image.
Actual behavior:
Google Cloud Run can’t access the credentials saved under /.streamlit/secrets.toml.
Debug info
Streamlit version: 1.22.0
Python version: 3.9.13
Using Conda? PipEnv? PyEnv? Pex? No to all
Additional information
If anyone can advise another way my Google Cloud Run service can access the credentials, I’m thankful. I’m new to this kind of deployment.
You must make sure that the secrets file (‘secrets.toml’) is present in the Docker image and available to your application before deploying a Streamlit app to Google Cloud Run. The Docker image created by Cloud Run by default does not automatically contain all of the files from your local directory.
You can take the following actions to fix the problem and make the “secrets.toml” file accessible in the deployed Cloud Run service:
Change your Dockerfile such that the “secrets.toml” file is explicitly copied into the Docker image. Make sure the file is included in the ‘COPY’ command and that it is in the proper location:
‘secrets.toml’ should be placed in the same directory as your Dockerfile.
Using the modified Dockerfile, create a fresh Docker image. Run the following command after making sure you are in the same directory as your Dockerfile and the’secrets.toml’ file:
docker build -t your-image-name .
By using this command, a fresh Docker image will be created with the’secrets.toml’ file included.
Upload the freshly created Docker image to a container registry that Google Cloud Run can access, such as Google Container Registry (GCR), Docker Hub, or a different private registry.
Use the revised Docker image from the container registry to deploy the Cloud Run service. During deployment, be careful to give the right image path.
The’secrets.toml’ file will be present in the Docker image and available to your Streamlit app running on Google Cloud Run after completing these instructions.
This doesn’t seem like good practice though. What if the image is built with GitHub Actions? We can’t store the secrets.toml file in the repository so how would we be able to copy the file during the build process?
If you are building the image via GitHub to then deploying on GCP, my suggestion is to use GCP Secrets Manager instead of Streamlit’s secrets.toml file.
Alternatively, you can use the gcloud CLI to send a local directory with a Dockerfile directly to Google for building, without going through GitHub. The image will be stored in GCP Artifact Registry.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.