Local LLM and Visualization Platform Deployment: A Practical Guide
This guide explains how to set up a local or intranet environment for question answering, knowledge base retrieval, and AI agent experiments using Docker Compose and Ollama. It covers prerequisites, model selection and resource planning, environment checks, environment variable configuration, application startup, troubleshooting, and local model service setup, including how to specify a dedicated model directory.
1. Deployment Goals and Prerequisites
This article is intended for readers who want to build a question answering, knowledge base retrieval, and agent experimentation environment on a local machine or intranet server. It uses Docker Compose to manage the application platform containers and Ollama as the local model runtime service. If a project uses a different container orchestration tool or model framework, command names will differ, but the troubleshooting approach remains the same.
Before deployment, prepare the following:
- Docker Desktop on Windows or macOS, or Docker Engine with the Compose plugin on Linux.
- At least 16 GB of memory, with 32 GB recommended. If a dedicated GPU is available, 8 GB or more of VRAM is preferable.
- At least 30 GB of free disk space outside the system drive for model files and container data.
- Network access to model repositories and container image registries.
The architecture described in this article has three layers: the model service loads models and provides interfaces, the application platform handles prompts, knowledge bases, and workflow orchestration, and the database and cache start with the container orchestration stack. When all three run on the same machine, resource contention is most obvious, so choose a model according to the reference values in the next section.
2. Choosing a Model and Planning Resources
Larger models generally produce better generation quality, but they also consume more memory and VRAM. The following table provides empirical reference values based on Q4 quantized versions, a default context length of about 4K to 8K, and single-user requests. Actual usage will vary with context length, concurrent requests, and the runtime framework.
| Model size | Quantization | Approximate model file size | Recommended memory or VRAM | Suitable scenarios |
|---|---|---|---|---|
| 3B | Q4 | 2 GB | 8 GB memory | Workflow validation, simple question answering |
| 7B | Q4 | 4.5 GB to 5 GB | 16 GB memory, or 8 GB VRAM | Daily question answering, basic knowledge bases |
| 14B | Q4 | About 9 GB | 24 GB memory, or 16 GB VRAM | More complex knowledge base question answering |
| 32B | Q4 | About 20 GB | More than 32 GB memory, or 24 GB VRAM | Long-text analysis, complex reasoning |
When choosing a model, first validate the entire chain with a 3B or 7B version. After confirming that everything works, switch to a larger model. The application platform, database, and cache also consume memory, so the model should not use more than about 70% of physical memory. After the model is running, use ollama ps to check the loaded model size and the CPU/GPU split.
Store model files in a dedicated directory rather than on the system drive. Ollama uses the OLLAMA_MODELS environment variable to specify the model directory. See Section 6 for setup details.
3. Checking the Base Environment
First, confirm that the container tools are running correctly:
docker --versiondocker compose versiondocker info
If docker info returns server-side information, the background service is running. If it reports that it cannot connect to the Docker daemon, start Docker Desktop first, or run sudo systemctl start docker on Linux.
When using Docker Desktop on Windows, confirm that WSL 2 is working properly. Run wsl -l -v in PowerShell; the VERSION column in the output should be 2. If containers fail to start, the cause is often that virtualization is not enabled or the WSL components are abnormal, rather than an application problem.
Check disk space:
df -h
Windows users can run Get-PSDrive -PSProvider FileSystem in PowerShell to view free space on each drive.
Place the project directory under an English path whenever possible, and avoid spaces, Chinese characters, and excessively deep directory levels. If the path contains special characters, container mounts may fail.
4. Getting the Project and Configuring Environment Variables
The application platform is usually provided as an open-source project or an archive. After extracting it, inspect the directory and confirm that it contains an orchestration configuration file such as docker-compose.yml, an environment variable template such as .env.example, and service documentation.
Do not edit the template file directly. Copy the template and edit the copy:
cp .env.example .env
The actual file name depends on the project documentation. When editing .env, focus on the following settings:
- Database username, password, and database name.
- Cache service address.
- External application port.
- Initial administrator account and password.
- Upload file directory.
- Secret keys and session signing configuration.
- Log level and runtime mode.
Production environments must not keep default keys, default passwords, or example credentials. You can generate a random key with OpenSSL:
openssl rand -hex 32
Put the output into the key configuration item. Even if the system runs only on an intranet, replace authentication information and restrict access to management ports by source.
5. Starting the Application Platform
In the directory containing the project’s orchestration configuration, run:
docker compose up -d
The -d flag runs the services in the background and returns immediately. The first startup performs several tasks: creating the application network, pulling images, creating database and cache containers, initializing data tables, mounting configuration and persistent directories, and finally starting the frontend, backend, and task services. The time required depends on network speed and image size, typically ranging from a few minutes to half an hour. During this period, do not repeatedly run the startup command or interrupt the terminal.
Check service status:
docker compose ps
The STATUS column for each core service should show Up. If a service shows Restarting or Exited, check its logs:
docker compose logs -f <service-name>
Replace <service-name> with the service name defined in docker-compose.yml, such as db, redis, or web. Common normal signals in the logs include PostgreSQL’s database system is ready to accept connections and Redis’s Ready to accept connections.
Troubleshoot in dependency order: check the database first, then the cache, then background tasks, and finally the frontend and API. If the database has not finished initializing, opening the page directly may result in a loading failure or a login page that does not display. This is a normal dependency wait.
To stop the services, use:
docker compose stop
stop preserves containers and data. docker compose down removes containers but keeps named volumes by default. Do not add the -v flag casually, because it deletes data volumes and the data cannot be recovered.
6. Installing and Starting the Local Model Service
Download the installer for your system from the official Ollama website. After installation, confirm the version:
ollama --version
If the command is not found, check the following in order: whether the installer completed, whether the terminal needs to be reopened, and whether the program directory has been added to PATH.
Specifying the Model Directory
On Linux, you can set the model directory and listening address through the systemd service:
sudo systemctl edit ollama.service
Add the relevant service settings in the editor. The model directory is controlled by the OLLAMA_MODELS environment variable, as mentioned in Section 2.
