Dockersupport for Microsofts NLWeb Fork: https://github.com/iunera/NLWeb/tree/docker
2.7K
Forked Repo (incl. Buildpipeline): https://github.com/iunera/NLWeb/tree/docker
Original Repo: https://github.com/microsoft/NLWeb
Background Information about NLWeb: https://www.iunera.com/kraken/machine-learning-ai/nlweb-enables-ai-powered-websites/
This repository contains a Dockerfile for building and running the NLWeb application, which turns your website into a knowledge base.
The Docker image is built using a 2-stage build process to minimize the final image size:
Here is the content of the Dockerfile:
# Stage 1: Build stage
FROM python:3.10-slim AS builder
WORKDIR /app
# Copy requirements file
COPY code/requirements.txt .
# Install build dependencies and Python packages
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc python3-dev && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Stage 2: Runtime stage
FROM python:3.10-slim
# Update system packages for security
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Create a non-root user and set permissions
RUN groupadd -r nlweb && \
useradd -r -g nlweb -d /app -s /bin/bash nlweb && \
chown -R nlweb:nlweb /app
USER nlweb
# Copy application code
COPY code/ /app/
COPY static/ /app/static/
# Remove local logs and .env file
RUN rm -r code/logs/* || true && \
rm -r .env || true
# Copy installed packages from builder stage
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Expose the port the app runs on
EXPOSE 8000
# Set environment variables
ENV PYTHONPATH=/app
ENV PORT=8000
# Command to run the application
CMD ["python", "app-file.py"]
When built using the multi-architecture build instructions, the Docker image can run on both:
This ensures that the image can be deployed on a wide range of hardware platforms without compatibility issues.
The Docker image includes several security features:
--no-install-recommends flag to minimize image sizeTo build the Docker image for your current architecture:
docker build -t iunera/nlweb:latest .
To build the Docker image for multiple architectures (ARM64 and AMD64), you can use Docker's buildx feature:
docker buildx build --platform linux/amd64,linux/arm64 -t iunera/nlweb:latest --push .
Note: The --push flag is required for multi-architecture builds. If you want to build without pushing to a registry, you can use the --load flag instead, but it only works for single-platform builds.
To run the Docker container:
docker run -p 8000:8000 iunera/nlweb:latest
This will start the NLWeb application and expose it on port 8000.
The application requires several environment variables to be set. You should pass these directly to the container without using a .env file:
docker run -p 8000:8000 \
-e AZURE_VECTOR_SEARCH_ENDPOINT="https://your-search.search.windows.net" \
-e AZURE_VECTOR_SEARCH_API_KEY="your-api-key" \
-e OPENAI_API_KEY="your-openai-key" \
iunera/nlweb:latest
For local development or testing, you can export all environment variables from your .env file using:
export $(grep -v '^#' code/.env | xargs)
docker run -it -p 8000:8000 \
-v ./data:/data \
-e AZURE_VECTOR_SEARCH_ENDPOINT=${AZURE_VECTOR_SEARCH_ENDPOINT} \
-e AZURE_VECTOR_SEARCH_API_KEY=${AZURE_VECTOR_SEARCH_API_KEY} \
-e OPENAI_API_KEY=${OPENAI_API_KEY} \
iunera/nlweb:latest
This command exports all non-commented variables from the code/.env file to your current shell session. However, for Docker deployments, it's recommended to pass environment variables directly to the container as shown above.
The following environment variables are required:
AZURE_VECTOR_SEARCH_ENDPOINT: Your Azure Vector Search endpointAZURE_VECTOR_SEARCH_API_KEY: Your Azure Vector Search API keyOPENAI_API_KEY: Your OpenAI API keySee the .env.template file in the code directory for all available configuration options, but remember to pass them as environment variables rather than using a .env file.
This repository includes a docker-compose.yaml file for easy deployment of the NLWeb application.
Here is the content of the docker-compose.yaml file:
services:
nlweb:
build:
context: .
dockerfile: Dockerfile
image: iunera/nlweb:latest
container_name: nlweb
ports:
- "8000:8000"
env_file:
- ./code/.env
environment:
- PYTHONPATH=/app
- PORT=8000
volumes:
- ./data:/data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
restart: unless-stopped
user: nlweb
To start the application using Docker Compose:
docker-compose up -d
This will build the Docker image if it doesn't exist and start the container in detached mode.
To stop the application:
docker-compose down
The docker-compose.yaml file is configured to automatically use environment variables from the code/.env file. This means you don't need to set environment variables in your shell or create a separate .env file in the same directory as the docker-compose.yaml file.
Simply make sure your code/.env file contains the necessary environment variables:
AZURE_VECTOR_SEARCH_ENDPOINT=https://your-search.search.windows.net
AZURE_VECTOR_SEARCH_API_KEY=your-api-key
AZURE_OPENAI_ENDPOINT=https://your-openai.azure.com/
AZURE_OPENAI_API_KEY=your-azure-openai-key
OPENAI_API_KEY=your-openai-key
Docker Compose will automatically load these variables from the code/.env file when you run:
docker-compose up -d
The docker-compose.yaml file is configured to mount a ./data directory from your host to /app/data in the container. This allows data to persist between container restarts.
To load data into the knowledge base when using Docker Compose:
docker-compose exec nlweb python -m tools.db_load <url> <name>
For example:
docker-compose exec nlweb python -m tools.db_load https://example.com/rss Example-Wiki
To load data into the knowledge base when using Docker directly:
docker exec -it <container_id> python -m tools.db_load <url> <name>
For example:
docker exec -it <container_id> python -m tools.db_load https://example.com/rss Example-Wiki
Once the container is running, you can access the application at:
http://localhost:8000
NLWeb can be deployed on Kubernetes clusters using the official Helm chart available at iunera/helm-charts.
# Add the iunera Helm repository
helm repo add iunera https://iunera.github.io/helm-charts/
# Update your Helm repositories
helm repo update
# Install the chart with the release name "my-release"
helm install my-release iunera/nlweb
The Helm chart provides:
For detailed configuration options and examples, visit the NLWeb Helm Chart repository.
For a detailed guide on installing and setting up NLWeb, check out our blog article: NLWeb Enables AI-Powered Websites. The article provides additional context and tips for getting started with NLWeb.
For more detailed information about the NLWeb application, please refer to the main documentation in the repository.
Content type
Image
Digest
sha256:42474c91d…
Size
217 MB
Last updated
over 1 year ago
docker pull iunera/nlweb