Deploying HuggingChat locally gives you the polished, multi-turn conversational interface of Hugging Face’s hosted service without routing a single token through public cloud servers. At 365Finds, our primary criterion for local AI setups is strict data isolation: if proprietary documents, internal prompts, or developer queries touch an external API, the deployment model fails.
The open-source repository behind HuggingChat is chat-ui, a SvelteKit application built by Hugging Face. Early versions required cumbersome JSON blocks with custom Jinja prompt templates just to wire up a local model. Today, chat-ui natively speaks standard OpenAI-compatible /v1 endpoints. This shift turns what used to be a brittle configuration puzzle into a predictable, containerized stack.
Architecture and Trade-offs
A complete, self-hosted HuggingChat deployment requires three distinct layers:
| Layer | Component | Recommended Container | Role |
|---|---|---|---|
| Interface | HuggingChat (chat-ui) | ghcr.io/huggingface/chat-ui:latest | SvelteKit web client and session manager |
| Persistence | MongoDB | mongo:latest | Stores conversations, user settings, and tokens |
| Inference | Local LLM Engine | ollama/ollama:latest or TGI | Executes model weights and exposes OpenAI-compatible /v1 API |
Hugging Face provides an all-in-one image named ghcr.io/huggingface/chat-ui-db that packages an embedded MongoDB instance inside the app container. While tempting for a five-minute test, 365Finds strongly advises against using the embedded database image for real team environments. Decoupling the database into a standalone MongoDB container prevents conversation history corruption during UI container updates and allows independent volume backups.
For the inference backend, choose based on hardware scale:
- Ollama: Best for workstations, laptops, and mixed developer environments. It handles quantization, CPU/GPU offloading, and multiple model swaps automatically.
- Text Generation Inference (TGI): Best for dedicated Linux servers with NVIDIA GPUs. Hugging Face builds TGI specifically for high-throughput production serving with continuous batching and FlashAttention.
Step 1: Prepare the Environment File
Create an isolated directory on your host machine and place an .env.local file inside it. This file configures the connection between chat-ui, the database, and your private endpoint:
mkdir -p local-huggingchat && cd local-huggingchat
touch .env.local docker-compose.yml
Populate .env.local with the following configuration:
# Database connection
MONGODB_URL=mongodb://mongo:27017
MONGODB_DB_NAME=chat-ui
# Inference backend configuration (OpenAI-compatible)
OPENAI_BASE_URL=http://ollama:11434/v1
OPENAI_API_KEY=ollama
# Application branding and settings
PUBLIC_APP_NAME="365Finds Private Chat"
PUBLIC_APP_DESCRIPTION="Private enterprise chat powered by local LLMs"
If you deploy Hugging Face TGI instead of Ollama, adjust OPENAI_BASE_URL to point to the TGI service:
OPENAI_BASE_URL=http://tgi:80/v1
OPENAI_API_KEY=tgi-local
Modern chat-ui queries the /models endpoint exposed by your inference server to discover available models automatically. You do not need to hardcode model architectures or Jinja prompt strings in your environment file.
Step 2: Configure Docker Compose
Create a docker-compose.yml file in the same directory. The configuration below provisions MongoDB, an Ollama inference backend with GPU pass-through, and the chat-ui frontend on a shared internal Docker network.
services:
mongo:
image: mongo:latest
container_name: mongo-chat-ui
restart: unless-stopped
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
chat-ui:
image: ghcr.io/huggingface/chat-ui:latest
container_name: chat-ui
restart: unless-stopped
ports:
- "3000:3000"
env_file:
- .env.local
environment:
- HOST=0.0.0.0
depends_on:
- mongo
- ollama
volumes:
mongo_data:
ollama_data:
If you do not have an NVIDIA GPU or the NVIDIA Container Toolkit installed, omit the entire deploy block under the ollama service. Ollama will fall back to CPU execution.
For teams running Hugging Face Text Generation Inference (TGI) with an NVIDIA GPU, replace the ollama service block with:
tgi:
image: ghcr.io/huggingface/text-generation-inference:latest
container_name: tgi
restart: unless-stopped
environment:
- MODEL_ID=meta-llama/Meta-Llama-3.1-8B-Instruct
- HF_TOKEN=${HF_TOKEN}
ports:
- "80:80"
volumes:
- tgi_data:/data
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
Step 3: Launch and Download Models
Start the stack in detached mode:
docker compose up -d
When Ollama starts for the first time, its internal model repository is empty. Because chat-ui dynamically fetches models from http://ollama:11434/v1/models, the web UI will show no available models until you pull at least one:
docker exec -it ollama ollama pull llama3.1:8b
To verify that Ollama is serving the model over the OpenAI compatibility layer, inspect the endpoint directly:
curl http://localhost:11434/v1/models
Once the JSON response lists llama3.1:8b, open your browser and navigate to http://localhost:3000. You will see the HuggingChat interface pre-loaded with your locally running model.
Operational Pitfalls and Configuration Checks
Three recurring errors derail private chat-ui deployments:
- The
localhostNetwork Trap: SettingOPENAI_BASE_URL=http://localhost:11434/v1inside.env.localfails. Inside a Docker network,localhostrefers to thechat-uicontainer itself, not the host machine or sibling containers. Always use container DNS names (such ashttp://ollama:11434/v1) orhttp://host.docker.internal:11434/v1if Ollama runs directly on the host OS. - Missing Database Persistence: Running without a named volume on MongoDB causes conversation history to vanish whenever the container restarts or upgrades. The volume mapping
mongo_data:/data/dbis mandatory. - Authentication and Access Control: By default, local
chat-uioperates without authentication; anyone with network access to port 3000 can initiate conversations and view local instances. For internal enterprise deployments, configure OpenID Connect by settingOPENID_CLIENT_ID,OPENID_CLIENT_SECRET, andOPENID_ISSUER_URLin.env.local.
The container logs can be inspected at any time using docker compose logs -f chat-ui to confirm that the SvelteKit server initialized without endpoint connection timeouts.