Colab에서 Streamlit 실행하는 방법 (cloudflared)

신영·2026년 3월 20일

Troubleshooting

목록 보기
2/3
post-thumbnail

목차
🚨 문제 상황
🔍 문제 원인 분석
⚡ 두 방법의 원리
💡 최종 해결 방법

🚨 문제 상황

Google Colab에서 Streamlit 앱 테스트를 위한 실행시 에러 발생


🔍 문제 원인 분석

Colab은 자체적으로 외부 포트를 직접 열 수 없기 때문에, colab에서 streamlit 실행을 하려면 터널링 툴을 이용해야 합니다.
터널링은 로컬(Colab 내부)에서 실행 중인 웹 서버를 공용 인터넷에서 접근 가능한 URL로 연결해 주는 방식입니다.

따로 계정 발급이 필요 없는 아래 두 가지 무료 방식을 시도해 보았습니다.

  • localtunnel: 단순히 TCP 연결을 프록시해주는 방식.
  • cloudflared: Cloudflare의 글로벌 네트워크를 활용한 역방향 프록시 터널.

⚙️ 시도 과정
시도 1: localtunnel 사용
참고 : https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399

# app.py로 실행하려는 파일 저장 후 아래 코드 실행
!npm install -g localtunnel 
!streamlit run app.py &>/content/logs.txt & 

import urllib 
print("Password/Enpoint IP for localtunnel is:",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip("\n"))

# 위 코드 실행하여 나온 IP 주소를 아래 코드 실행 후 나온 링크에 접속하여 입력
!lt --port 8501 --subdomain youtube-blog-1234 &
  • Colab 터널 URL 접속 성공
  • 그러나 입력창, 사이드바, 진행상황 표시 등 일부 컴포넌트 무한 로딩

시도 2: cloudflared 사용

!wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -O cloudflared.deb 
!dpkg -i cloudflared.deb || apt-get -f install -y 
!streamlit run app.py --server.address 0.0.0.0 --server.port 8501 &>/content/streamlit.log & 
!cloudflared tunnel --url http://localhost:8501 --no-autoupdate > cf.log 2>&1 &

⚡ 두 방법의 원리

localtunnel

  • Node.js 기반 간단한 오픈소스 터널링 툴
  • 클라이언트(localtunnel CLI) → localtunnel 서버 → Colab 내부 포트로 요청 전달
  • 장점: 설치/사용이 매우 간단, 별도 계정 불필요
  • 단점: Colab 환경에서 WebSocket 업그레이드가 불안정 → Streamlit UI 일부 로딩 실패

cloudflared

  • Cloudflare Tunnel(Argo Tunnel)의 오픈소스 클라이언트
  • Colab 내부 서버와 Cloudflare 글로벌 네트워크 사이에 안정적인 역방향 프록시 구축
  • 장점: WebSocket/HTTP/2 안정적 지원, 빠른 전송 속도
  • 단점: 패키지 설치가 한 단계 더 필요

💡 최종 해결 방법

  • Colab에서 Streamlit 실행 시, localtunnel 대신 cloudflared 사용
  • 특히 입력창, 차트, 사이드바 등 WebSocket 기반 컴포넌트를 활용하려면 cloudflared가 사실상 필수
profile
Human×Tech Bridge Builder | EdTech | AI Service Developer

0개의 댓글