FastAPI + Streamlit 프로젝트를 5분 안에 실행하는 방법입니다. 해당 가이드에서는 Docker를 사용하는 방법과 Local로 실행하는 2가지 방법을 설명합니다.
- 방법 1: Docker 사용 (추천) 🐳
- 방법 2: 로컬 실행 💻
docker --version
docker-compose --version설치가 안 되어 있다면: https://www.docker.com/get-started 을 참고해주세요
환경이 제대로 설정되어 있는지, 다음 script를 실행해서 확인합니다.
./test_docker.sh옵션 A - Docker Compose 직접 사용:
docker-compose up --build옵션 B- Docker 이미지별로 실행(비권장):
- 🎨 Streamlit: http://localhost:8501
- 🚀 FastAPI: http://localhost:8000
- 📚 API 문서: http://localhost:8000/docs
# Ctrl+C 또는
docker-compose downpython -m venv venv
# Mac/Linux
source venv/bin/activate
# Windows
venv\Scripts\activatepip install -r backend/requirements.txt
pip install -r frontend/requirements.txtMac/Linux:
chmod +x run_all.sh
./run_all.shWindows:
run_all.bat또는 개별 실행:
터미널 1 (백엔드):
python run_backend.py터미널 2 (프론트엔드):
python run_frontend.py- 🎨 Streamlit: http://localhost:8501
- 🚀 FastAPI: http://localhost:8000
- 📚 API 문서: http://localhost:8000/docs
- http://localhost:8501 접속
- 사이드바에서 "사용자 관리" 선택
- "사용자 생성" 탭 클릭
- 정보 입력:
- 사용자명:
testuser - 이메일:
test@example.com - 비밀번호:
password123
- 사용자명:
- "생성" 버튼 클릭
# 사용자 생성
curl -X POST "http://localhost:8000/api/v1/users/" \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}'
# 모든 사용자 조회
curl http://localhost:8000/api/v1/users/
# 아이템 생성
curl -X POST "http://localhost:8000/api/v1/items/?owner_id=1" \
-H "Content-Type: application/json" \
-d '{
"title": "노트북",
"description": "맥북 프로",
"price": 2500000
}'
# 모든 아이템 조회
curl http://localhost:8000/api/v1/items/- http://localhost:8000/docs 접속
- API 엔드포인트 선택
- "Try it out" 클릭
- 파라미터 입력
- "Execute" 실행
만약, 아래 문제가 발생할 경우, 다음을 확인해주세요!!
# Mac/Linux
lsof -ti:8000 | xargs kill -9
lsof -ti:8501 | xargs kill -9
# 또는 Docker 컨테이너 정리
docker-compose down- 백엔드가 실행 중인지 확인
- http://localhost:8000/health 접속 테스트
- Docker 사용 시 컨테이너 로그 확인:
docker-compose logs backend
코드를 수정해도 내용이 반영되지 않는 문제가 발생할 경우, image build cache를 지우고 실행해보세요.
# Docker 이미지 재빌드
docker-compose build --no-cache
docker-compose up- 전체 README - 상세한 프로젝트 문서
- Docker 가이드 - Docker 사용법 상세 가이드
- FastAPI 문서
- Streamlit 문서
이제 FastAPI + Streamlit 프로젝트가 실행되었습니다! 궁금한 점이 있으면 이슈를 등록해주세요. 😊