This guide explains how to dockerize and run the RAG QA System using Docker.
- Docker installed on your system
- Docker Compose (optional, for easier management)
- The T5 model downloaded to
/home/fg12/.cache/huggingface/hub/models--t5-small
# Make the build script executable (if not already done)
chmod +x build_docker.sh
# Run the build script
./build_docker.shThis script will:
- Copy the T5 model from your local cache to the project
- Build the Docker image
- Provide instructions for running the container
After building, you can run the container in several ways:
docker run -p 8501:8501 rag-qa-systemdocker-compose updocker-compose up -dOnce running, the Streamlit application will be available at:
- Local: http://localhost:8501
- Network: http://your-server-ip:8501
If you prefer to build manually:
# Create models directory
mkdir -p models
# Copy the T5 model
cp -r /home/fg12/.cache/huggingface/hub/models--t5-small models/docker build -t rag-qa-system .docker run -p 8501:8501 rag-qa-systemThe docker-compose.yml file includes:
- Port mapping: Maps container port 8501 to host port 8501
- Volume mounting: Mounts
sample_data.jsonfor easy updates - Health checks: Monitors application health
- Restart policy: Automatically restarts on failure
You can customize the container behavior with environment variables:
docker run -p 8501:8501 \
-e PYTHONUNBUFFERED=1 \
-e STREAMLIT_SERVER_PORT=8501 \
rag-qa-systemFor development, you can mount additional volumes:
docker run -p 8501:8501 \
-v $(pwd)/sample_data.json:/app/sample_data.json:ro \
-v $(pwd)/custom_data:/app/custom_data:ro \
rag-qa-systemIf the model fails to load:
- Check model path: Ensure the model is copied to
models/directory - Verify model structure: The model should be in
models/models--t5-small/snapshots/... - Check permissions: Ensure the model files are readable
If port 8501 is already in use:
# Use a different port
docker run -p 8502:8501 rag-qa-systemFor large models, you might need to increase Docker memory limits:
docker run -p 8501:8501 \
--memory=4g \
--memory-swap=4g \
rag-qa-systemTo enable GPU support (if available):
docker run -p 8501:8501 \
--gpus all \
rag-qa-systemAfter making changes to the code:
# Rebuild the image
docker build -t rag-qa-system .
# Or force rebuild without cache
docker build --no-cache -t rag-qa-system .# View container logs
docker logs <container_id>
# Follow logs in real-time
docker logs -f <container_id># Execute commands inside the container
docker exec -it <container_id> /bin/bash
# Run Python commands
docker exec -it <container_id> uv run python -c "print('Hello from container')"For production deployment:
- Use a production base image: Consider using
python:3.11-slimorpython:3.11-alpine - Add security: Run as non-root user (already implemented)
- Optimize size: Use multi-stage builds to reduce image size
- Add monitoring: Include health checks and logging
- Use secrets: Store sensitive data in Docker secrets or environment variables
rag_project/
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .dockerignore # Files to exclude from build
├── build_docker.sh # Build script
├── models/ # Local model storage
│ └── models--t5-small/ # T5 model files
├── rag_project/ # Application code
├── streamlit_app.py # Streamlit application
├── sample_data.json # Sample Q&A data
└── pyproject.toml # Project dependencies