Host a Streamlit or Gradio App: Dockerfile, Push, HTTPS URL

Streamlit hosting and Gradio hosting on your own container: secrets in environment variables, a database or an API next to it, and a custom domain when you need one. One rule decides the plan: Streamlit's browser session runs over a WebSocket, which the free tier does not pass, so a Streamlit app runs on an Always-On container; Gradio talks to the browser over plain HTTP (server-sent events) and runs under the free-tier rules. The exact Dockerfile for each framework is below.

Gradio: free tier, 4 containers, 512 MB each, 100 hours a month, 10 deploys a day, no credit card. Streamlit: Always-On, $12 a month per container (₹1,119 in India), no sleep, WebSockets on. Medium (2 GB) from $25, dedicated GPU from $499.

Last verified 22 October 2026 against the free-tier docs, the WebSocket rule in the deployment code and at the edge, and the Streamlit Community Cloud and Hugging Face documentation read on 28 September 2026.

Where to Host a Streamlit or Gradio App in 2026

The four realistic options, with the limits each one states on its own documentation as of 28 September 2026. Two of them changed recently and most tutorials online have not caught up.

Host Free plan Resources Sleeps after Private apps Needs
SnapDeploy4 containers, 100 container-hours a month, no card. Gradio runs free; Streamlit needs Always-On ($12 a month) because its UI runs over a WebSocket512 MB, 0.25 vCPU free; 2 GB and 4 GB paid; dedicated T4 or A10G GPU paid. Uploaded images up to 2 GB free, up to 10 GB on Always-On15 minutes idle; ~60 s wake; none on Always-OnYesA Dockerfile and Always-On for Streamlit; a GitHub repo or an image upload
Streamlit Community CloudFree; unlimited public apps, one private appAbout 0.078 to 2 CPU cores and 690 MB to 2.7 GB RAM, shared (their Feb 2024 figures)12 hours without traffic; any viewer can wake itOneA GitHub account with admin rights on the repo; apps hosted in the US only
Hugging Face SpacesStatic Spaces free; Gradio and Docker Spaces need PRO ($9/mo) or Team ($20/user/mo); free personal accounts may host up to 2 Gradio Spaces on ZeroGPUCPU Basic: 2 vCPU, 16 GB, 50 GB non-persistent48 hours idle on free hardware; visitor restarts itProtected and private visibility need a paid planStreamlit runs as a Docker Space; no Streamlit SDK option any more
Render free web service750 instance-hours a month per workspace, no card512 MB, 0.1 CPU15 minutes; about a minute to wakeYesA start command; 5 GB bandwidth a month on the Hobby workspace

Isolation: every SnapDeploy container, free tier included, runs as its own AWS Fargate task with a reserved 0.25 vCPU and 512 MB; AWS runs each task on a single-use, single-tenant compute instance. Streamlit says all Community Cloud users share the same resources, 0.078 to 2 cores and 690 MB to 2.7 GB per app. Hugging Face's CPU Basic hardware is 2 vCPU and 16 GB, but Gradio and Docker Spaces now need a paid plan. Render's free instance is 0.1 CPU and 512 MB.

Sources: docs.streamlit.io (manage your app: app hibernation and resource limits; status and limitations) and the Streamlit forum FAQ of 1 March 2024 on private apps; huggingface.co/docs/hub (Spaces overview, Spaces GPU and sleep settings) and huggingface.co/pricing; render.com/docs/free, render.com/docs/compute-plans and render.com/pricing; aws.amazon.com/fargate/faqs (task isolation).

Deploy a Streamlit App on SnapDeploy

Streamlit needs its own server command, so this one takes a five-line Dockerfile. The automatic Python build runs python app.py, which is right for Flask and Gradio but does not start Streamlit.

Before you open the app: switch the container to Always-On.

Streamlit's UI connects to its server over a WebSocket, and the free tier does not pass WebSocket connections. On a free container the page stays blank, and the browser's reconnect attempts can trip the shared domain's 100-requests-a-minute guard, which answers 429 for 10 minutes. Always-On ($12 a month per container, ₹1,119 in India) turns WebSockets on, removes the sleep and allows a custom domain. Gradio does not need this: it sends results over server-sent events, plain HTTP.

1.Add a Dockerfile next to app.py

The platform sets a PORT environment variable in every container. Streamlit must listen on it and on all interfaces; the shell form of the command is what expands the variable.

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["sh", "-c", "streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0 --server.headless=true"]

requirements.txt must list streamlit and whatever the app imports. Pin versions; a build that pulls a new major version of pandas is the most common reason a working app breaks on redeploy.

2.Move secrets to environment variables

Community Cloud uses a secrets file; here the same values go into the container's environment variables in the dashboard and are read with os.environ. Nothing secret goes in the repository.

import os
import streamlit as st

api_key = os.environ["OPENAI_API_KEY"]
st.title("Sales dashboard")

3.Connect the repository and deploy

Sign in, choose Deploy from GitHub, pick the repository and branch, add the variables, deploy. The build log streams live; when the image is pushed the container starts and the app is at https://<name>.containers.snapdeploy.app. The health check accepts Streamlit's root page, so no extra route is needed. Then switch the container to Always-On from its card: without it the page stays blank, because the free tier does not pass Streamlit's WebSocket. Every push to the branch redeploys.

4.Pick the size that fits the data

A dashboard over a CSV of a few megabytes runs in a Small container (512 MB, $12 a month on Always-On). A large DataFrame, a local model or image processing wants Medium (2 GB, 1 vCPU, $25 a month) or Large (4 GB, 2 vCPU, $45). A model that needs a GPU runs on a dedicated T4 ($499 a month) or A10G ($999) with the same Dockerfile flow. Sizes change without a rebuild.

Deploy a Gradio App on SnapDeploy

A Gradio app runs on the free tier: Gradio sends results to the browser over server-sent events, plain HTTP, so the WebSocket rule does not apply. No Dockerfile is required either: Gradio starts from a normal Python script, so it fits the automatic build. Two things matter: bind to all interfaces and read the port from the environment.

1.Make app.py launch on 0.0.0.0 and PORT

import os
import gradio as gr

def greet(name):
    return f"Hello, {name}!"

demo = gr.Interface(fn=greet, inputs="text", outputs="text")

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0",
                server_port=int(os.environ.get("PORT", 7860)))

With requirements.txt listing gradio, the automatic Python build installs it and runs python app.py. No Dockerfile is required. Do not use share=True: that creates a temporary tunnel link from Gradio's servers, and the container already has a permanent HTTPS address.

2.Or add a Dockerfile for control

When you need a specific Python version, a system package such as ffmpeg, or model weights baked into the image, commit a Dockerfile and it is used as written.

FROM python:3.11-slim
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["python", "app.py"]

3.Models, weights and the GPU question

Small models load fine into a Medium container. Anything that expects CUDA belongs on a dedicated GPU instance, where the same Dockerfile runs with the NVIDIA runtime and one-click PyTorch, Hugging Face and vLLM templates exist. The container's filesystem is ephemeral, so download weights at build time into the image or at start from object storage, not into a folder you expect to survive a restart.

When Community Cloud or Spaces Is Not Enough

Both incumbents are good at what they are for: public demos. These are the cases where people move to a container.

  • More than one private app. Community Cloud allows one private app per account and says it has no plans to sell more. On Hugging Face, protected and private Spaces are paid-plan features. Here every container can serve a private repository; for Streamlit that container is Always-On, for Gradio it can be free.
  • A Gradio app without a paid Hugging Face plan. Creating a Gradio or Docker Space now requires PRO or a Team plan, apart from up to two ZeroGPU Spaces for personal accounts in good standing. A Gradio container on SnapDeploy's free tier has no such gate.
  • Your own domain. Neither free incumbent gives you one on the free plan for an app. Always-On does, with the certificate issued for you.
  • A database or an API next to the app. A dashboard that reads from PostgreSQL, or a Gradio front end over a FastAPI backend, is two containers on one account, and managed PostgreSQL, MySQL, MongoDB, Redis and RabbitMQ are add-ons.
  • No GitHub. Community Cloud requires GitHub with admin rights on the repository. Here you can upload a docker save tarball instead.
  • A guaranteed wake-up story for demos. Free containers sleep after 15 minutes, which is shorter than Community Cloud's 12 hours. For a demo day, a $1 Sprint Pack keeps one container awake for 24 hours; for a client-facing app, Always-On never sleeps.

What the Free Tier Gives a Python App

Free Python hosting here follows the same rules as any container; the complete list is on the free-tier page.

  • 4 containers, 512 MB and 0.25 vCPU each, no credit card. Medium and Large sizes run on Always-On.
  • No WebSockets on the free tier. The free edge answers WebSocket connections with 403. Streamlit's UI needs one, so a Streamlit container runs on Always-On; Gradio, Flask, Django and FastAPI apps talk plain HTTP and are not affected.
  • 100 container-hours a month, counted only while a container is awake. A dashboard used a few times a day uses a fraction of it.
  • Sleep after 15 idle minutes, wake in about 60 seconds when someone opens the app in a browser. A script or a scheduled job does not wake it.
  • 10 deploys a day (5 per rolling 12 hours), failed builds included. Builds time out at 60 minutes; most Python builds finish in a few minutes.
  • HTTPS on day one, logs and CPU/memory metrics in the dashboard, runtime environment variables set without a rebuild.
  • Ephemeral disk. Uploaded files and caches vanish on restart; keep state in a database add-on or object storage.

Streamlit and Gradio Hosting Questions, Answered

Can I host a Streamlit app for free on SnapDeploy?

You can build and deploy it for free, but a Streamlit app does not open on the free tier: Streamlit's browser session runs over a WebSocket, and the free tier does not pass WebSocket connections. Switch the container to Always-On ($12 a month, ₹1,119 in India) and the app opens, stays up 24/7 and can take a custom domain. Gradio is not affected: Gradio sends results to the browser over server-sent events, which is plain HTTP, so a Gradio app runs under the normal free-tier rules.

Do I need a Dockerfile for Streamlit?

Yes, a short one. The automatic Python build starts an app with python app.py, which does not start Streamlit's server. A five-line Dockerfile that installs requirements.txt and runs streamlit run with the platform's PORT variable is all that is needed; it is on this page.

Do I need a Dockerfile for Gradio?

Not necessarily. If app.py calls demo.launch with server_name 0.0.0.0 and the port read from the PORT environment variable, the automatic Python build, which runs python app.py, starts it. A Dockerfile gives you control over the Python version and system packages, and is shown on this page too.

Does the app need a /health route?

No. The platform's health check tries the common health paths and then the root path, and for Python apps any HTTP response counts as alive. Streamlit and Gradio both answer the root path, so no extra route is needed.

How is this different from Streamlit Community Cloud?

Community Cloud is free, needs a GitHub account, allows unlimited public apps but one private app, and hibernates an app after 12 hours without traffic. On SnapDeploy a Streamlit app runs on an Always-On container ($12 a month): no sleep, as many private apps as you have containers, an image upload instead of GitHub if you prefer, a custom domain, and a database or an API next to the app. The free tier's 15-minute sleep applies to Gradio and other plain-HTTP apps, which it runs as private apps at no cost.

How is this different from Hugging Face Spaces?

Static Spaces are free for everyone, but creating a Gradio or Docker Space now requires a paid plan: PRO at $9 a month for personal accounts, Team or Enterprise for organisations, with an exception of up to 2 Gradio Spaces on ZeroGPU for free personal accounts in good standing. Free CPU hardware sleeps after 48 hours idle. SnapDeploy's free tier has no plan requirement for a Gradio container; the trade-off is a 15-minute sleep and 512 MB.

Is 512 MB enough for a Streamlit or Gradio app?

For a dashboard over a small dataset or a demo that calls an API, yes. Pandas on a large frame, a local model or heavy image work needs Medium (2 GB, $25 a month) or Large (4 GB, $45). Models that need a GPU run on a dedicated T4 or A10G instance.

Where do I put API keys and secrets?

In the container's environment variables in the dashboard, never in the repository. Read them with os.environ in Python. Values whose names look like secrets are masked in the dashboard.

Proud Member Of

As Seen On

Put Your Streamlit or Gradio App Online Today

Gradio on the free tier, no credit card. Streamlit on Always-On from $12 a month, with WebSockets, no sleep and your own domain.

Deploy Free Today
FIRST OF ITS KIND

Sprint Pack — $1 for 24 hours

The first managed container PaaS to offer a one-time 24-hour Always-On pass under $5. Everything in Always-On Small for one Small (512 MB) container — runs 24/7, no daily deploy limit, WebSockets & real-time apps. No subscription, no auto-renewal.

Need a managed database too? DB Sprint Pack — $1 / 12h for Postgres, MySQL, MariaDB, Mongo, Redis, or RabbitMQ.