Hi! I have an app deployed to the Streamlit cloud and intend to migrate it to Google Cloud Run. I have succesfully deployed it on there but I have been having a couple of issues:
- Closing WebSocket: every few minutes I get a WebSocket onclose warning;
- Front-end assets missing: a loading indicator doesn’t show up at all and interactable boxes and buttons’ highlights aren’t the right color.
And these are just the problems I could find. Here is the version hosted on the streamlit cloud: https://tidesat.streamlit.app/ and here is the version hosted on GCP: https://teste-repo-clonado4-552822684594.us-central1.run.app/
Thanks in advance!
Hey, thanks for sharing your question and both app links! Migrating from Streamlit Community Cloud to Google Cloud Run is a great step, but it does come with some gotchas. Let’s break down your issues:
-
WebSocket disconnects: Frequent WebSocket closures on Cloud Run are common due to idle timeouts, load balancer settings, or Cloud Run’s stateless nature. Streamlit relies on persistent WebSocket connections, and Cloud Run may terminate these after a few minutes of inactivity or due to scaling events. There’s no official Streamlit config to change this, but you can try increasing the timeoutSeconds in your Cloud Run YAML (up to 3600 seconds), and ensure session affinity is enabled if possible. However, some disconnects are expected due to Cloud Run’s design (see forum discussion, Cloud Run docs).
-
Front-end assets and styling issues: Missing loading indicators and incorrect widget highlights often result from misconfigured static file serving, CORS, or proxy settings. Make sure you’re not using port 3000, and try running Streamlit with these flags in your Dockerfile or entrypoint:
streamlit run app.py --server.port=8080 --server.address=0.0.0.0 --server.enableCORS=false --server.enableWebsocketCompression=false --server.enableXsrfProtection=false
Also, check that your Docker container exposes the correct port (usually 8080 for Cloud Run), and that your config.toml is present and correct in the deployed image (see deployment troubleshooting, App Engine/Cloud Run tips).
If you can share your Dockerfile and deployment YAML, the community can help debug further! Also, make sure your requirements.txt and config.toml are included in your Docker build context. Community members, feel free to jump in with your Cloud Run tips!
Sources: