Self-Hosting an AI Assistant on Windows with Docker and LLM API Integration

    This guide shows how to run a self-hosted AI assistant on Windows in a Docker container and connect it to an OpenAI-compatible large language model API. It covers system requirements, installing WSL 2 and Docker Desktop, storing the API key securely in a local configuration file, starting the container with a persistent data volume, and verifying the setup. The approach avoids downloading and running remote scripts, so no PowerShell execution policy changes are needed.

    Introduction: Deployment Approach

    Many developers want to run an AI assistant on their own machines. This offers two direct benefits: conversation records and configuration stay local, and the model service can be changed at any time. A common method is to download an installation script and run it directly in an administrator terminal. The problem with this method is that the script runs without review, and it is difficult to roll back if something goes wrong.

    This guide takes a different approach. The server program runs as a Docker container. All steps use only Docker commands and built-in PowerShell commands, and no remote script is downloaded or executed. As a result, you do not need to change the PowerShell execution policy. After completing these steps, the system has only one additional container and one data volume. Deleting them restores the system to its original state.

    1. Environment Setup

    1.1 System and Hardware Requirements

    Confirm the following:

    • Your operating system is 64-bit Windows 10 version 22H2 or later, or Windows 11.
    • We recommend at least 8 GB of RAM. This value is based on practical experience and is not an official minimum. With less memory, the container may respond slowly.
    • We recommend keeping at least 5 GB of free disk space for the images and conversation data.

    1.2 Enabling WSL 2 and Installing Docker Desktop

    Docker Desktop on Windows depends on WSL 2. Open PowerShell as an administrator and run:

    1. wsl --install

    Restart your computer after the command finishes. Then download Docker Desktop from the official Docker website and install it. After installation, open Docker Desktop and wait until the status in the lower-left corner shows that it is running.

    Run the following two commands in PowerShell to confirm that Docker works:

    1. docker version
    2. docker run --rm hello-world

    If the second command prints a message such as “Hello from Docker!”, the Docker environment is working correctly.

    2. Obtaining and Securely Storing Your API Key

    2.1 Creating an API Key

    Log in to the console of the large language model platform you have chosen, then click the option to create a key on the API key management page. Most platforms show the full key only once, at creation time, so copy and save it immediately. Follow the platform’s actual page layout, as it may differ from this guide.

    2.2 Writing the Local Configuration File

    Create the working directory and configuration file:

    1. New-Item -ItemType Directory -Force "$env:USERPROFILE\ai-assistant" | Out-Null
    2. notepad "$env:USERPROFILE\ai-assistant\openwebui.env"

    Add the following two lines to the file. This guide uses the OpenAI API endpoint as an example. If you use another platform that is compatible with the OpenAI API, replace the address with the base URL given in that platform’s documentation.

    1. OPENAI_API_BASE_URL=https://api.openai.com/v1
    2. OPENAI_API_KEY=your-api-key

    After saving the file, restrict read access so that only the current user can open it:

    1. icacls "$env:USERPROFILE\ai-assistant\openwebui.env" /inheritance:r /grant:r "$env:USERNAME:F"

    Keep the following points in mind:

    • Do not put the key in project code, screenshots, or chat logs.
    • If this directory is inside a Git repository, add openwebui.env to .gitignore.
    • If a key is leaked, immediately delete it in the platform console and create a new one.

    3. Pulling the Image and Starting the Container

    3.1 Checking Port Usage

    This guide uses port 3000 on the local machine by default. Run the following command to check whether the port is already in use:

    1. Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue

    If the command returns no output, the port is free. If it returns output, choose another port, such as 3001, and update the port mapping in the command in Section 3.2 to match.

    3.2 Pulling the Image and Starting the Container

    First, pull the official image, then start the container:

    1. docker pull ghcr.io/open-webui/open-webui:main
    2. docker run -d --name open-webui `
    3. --env-file "$env:USERPROFILE\ai-assistant\openwebui.env" `
    4. -p 127.0.0.1:3000:8080 `
    5. -v open-webui:/app/backend/data `
    6. --restart unless-stopped `
    7. ghcr.io/open-webui/open-webui:main

    The parameters in this command do the following:

    • --env-file reads the model endpoint and API key from the configuration file, so the key does not appear in the command history.
    • -p 127.0.0.1:3000:8080 binds the service only to the local loopback address. Other devices on the same local network cannot access it. This is the recommended default.
    • -v open-webui:/app/backend/data stores conversation data in a Docker volume named open-webui. The data is kept even if the container is recreated.
    • main is the tag for the latest development branch. For long-term stable operation or easier rollback, select a specific version tag on the project’s GitHub Releases page, replace main with that tag, and then run the command.

    Download time depends on your network conditions, so follow the terminal output for progress. After startup, view the logs to confirm that the service has started listening:

    1. docker logs -f open-webui

    Once you see output indicating that the service is listening, press Ctrl + C to exit the log view.

    3.3 Recording the Image Digest

    For future reproduction and rollback, record the digest of the current image:

    1. docker image inspect ghcr.io/open-webui/open-webui:main --format '{{index .RepoDigests 0}}'

    Save the output in a note file in your working directory.

    4. Verifying the Installation and Connecting the Model

    4.1 Checking Container Status

    1. docker ps --filter name=open-webui

    If the STATUS column shows Up, the container is running.

    4.2 Opening the Web Interface and Creating an Administrator

    Open http://127.0.0.1:3000 in your browser. On the first visit, you need to register an account. The first registered account usually becomes the administrator. Use a strong password and keep it safe.

    4.3 Testing the API Key Directly

    Before entering the key in the interface, confirm that the key itself is valid by using a script. The following command reads the key from the configuration file and calls the model list endpoint. It prints only the number of available models and does not display the key:

    ```powershell
    $key = (Get-Content “$env:USERPROFILE\ai-assistant\openwebui.env” |
    Where-Object { $_ -like ‘OPENAI_API_KEY=*’ }) -replace ‘^OPENAI_API_KEY=’, ‘’