AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Deploy the Open-Source HuggingChat UI Locally with Docker and Private LLM Endpoints

Thiago Viana · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

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:

LayerComponentRecommended ContainerRole
InterfaceHuggingChat (chat-ui)ghcr.io/huggingface/chat-ui:latestSvelteKit web client and session manager
PersistenceMongoDBmongo:latestStores conversations, user settings, and tokens
InferenceLocal LLM Engineollama/ollama:latest or TGIExecutes 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:

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:

  1. The localhost Network Trap: Setting OPENAI_BASE_URL=http://localhost:11434/v1 inside .env.local fails. Inside a Docker network, localhost refers to the chat-ui container itself, not the host machine or sibling containers. Always use container DNS names (such as http://ollama:11434/v1) or http://host.docker.internal:11434/v1 if Ollama runs directly on the host OS.
  2. 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/db is mandatory.
  3. Authentication and Access Control: By default, local chat-ui operates without authentication; anyone with network access to port 3000 can initiate conversations and view local instances. For internal enterprise deployments, configure OpenID Connect by setting OPENID_CLIENT_ID, OPENID_CLIENT_SECRET, and OPENID_ISSUER_URL in .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.

References