English | 简体中文 | 繁體中文 | Русский
Open-source, self-hosted local LLM server.
Run local language models on your own hardware with InferCrate. Powered by Ollama, it provides the native Ollama API and an OpenAI-compatible /v1 API subset, with API-key authentication, model management, and CPU or NVIDIA GPU deployment.
Previously known as
docker-ollama, maintained by hwdsl2. The Docker image name remainshwdsl2/ollama-server.
Features:
- OpenAI-compatible API: a
/v1API subset for compatible OpenAI SDKs and apps, alongside the native Ollama API. - Secure by default: Caddy enforces Bearer token authentication for API access; an API key is auto-generated on first start and stored in the persistent volume.
- Model pre-pull: pre-pull models on first start with the
OLLAMA_MODELSenvironment variable. - Model management: via a helper script (
ollama_manage). - CPU and GPU support: run on CPU or use the
:cudaimage for NVIDIA GPU acceleration. - Lightweight CPU image: based on Debian Trixie (slim); approximately 80 MB.
- Automated builds: images are automatically built and published through GitHub Actions.
Also available as part of the Self-Hosted AI Stack, which deploys a complete self-hosted AI stack with a single command.
📘 The Self-Hosted AI Builder’s Guide shows how to configure this service and use it with other self-hosted AI tools. Kindle · paperback · Google Play
Step 1. Start InferCrate:
docker run \
--name ollama \
--restart=always \
-v ollama-data:/var/lib/ollama \
-p 11434:11434/tcp \
-d hwdsl2/ollama-serverOn first start, an API key is auto-generated and displayed in the container logs. All API requests require this key.
Note
For internet-facing deployments, use a reverse proxy to add HTTPS. Also replace -p 11434:11434/tcp with -p 127.0.0.1:11434:11434/tcp in the docker run command above, to prevent direct access to the unencrypted port.
Step 2. Get the API key:
# View the key in the container logs
docker logs ollama
# Or retrieve it for use in scripts
infer_api_key="$(docker exec ollama ollama_manage --getkey)"The API key is displayed in a box labeled InferCrate API key. To display it again at any time:
docker exec ollama ollama_manage --showkeyStep 3. Pull a model:
docker exec ollama ollama_manage --pull llama3.2:3bTip: To pull one or more models automatically on first start, set OLLAMA_MODELS before running the container:
docker run \
--name ollama \
--restart=always \
-v ollama-data:/var/lib/ollama \
-p 11434:11434/tcp \
-e OLLAMA_MODELS=llama3.2:3b \
-d hwdsl2/ollama-serverOr add OLLAMA_MODELS=llama3.2:3b to your ollama.env file (see Environment variables).
Step 4. Test with the API:
infer_api_key="$(docker exec ollama ollama_manage --getkey)"
# List models
curl http://localhost:11434/api/tags \
-H "Authorization: Bearer $infer_api_key"
# Chat completion (streaming)
curl http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $infer_api_key" \
-d '{"model": "llama3.2:3b", "messages": [{"role": "user", "content": "Hello!"}]}'Note: The docker exec management commands (ollama_manage) do not require the API key.
To learn more about how to use this image, read the sections below.
- 📬 Get project updates and free deployment guides (1–2 emails/month)
- 💬 Join the r/selfhostedstack community for discussions and showcases
- ⭐ Star the repository if you find it useful — it helps others discover it
Self-hosted VPN & networking projects
- A Linux server (local or cloud) with Docker installed
- Sufficient disk space for models (3B models ≈ 2GB, 7B models ≈ 4–5GB, 14B+ models ≈ 8–10GB+)
- Sufficient RAM to run models (3B models ≈ 2–4GB, 7B models ≈ 6–8GB, 14B+ models ≈ 12–16GB+)
- TCP port 11434 (or your configured port) accessible
For GPU acceleration (:cuda image):
- NVIDIA GPU with CUDA support
- NVIDIA driver 575.57.08+ (Linux) or 576.57+ (Windows) installed on the host
- NVIDIA Container Toolkit installed
- The
:cudaimage supportslinux/amd64only
Get the trusted build from the Docker Hub registry:
docker pull hwdsl2/ollama-serverFor GPU support:
docker pull hwdsl2/ollama-server:cudaAlternatively, you may download from Quay.io:
docker pull quay.io/hwdsl2/ollama-server
docker image tag quay.io/hwdsl2/ollama-server hwdsl2/ollama-serverSupported platforms: linux/amd64 and linux/arm64. The :cuda tag supports linux/amd64 only.
All variables are optional. If not set, secure defaults are used automatically.
This Docker image uses the following variables, that can be declared in an env file (see example):
| Variable | Description | Default |
|---|---|---|
OLLAMA_API_KEY |
API key for authenticating requests (auto-generated if not set) | Auto-generated |
OLLAMA_PORT |
TCP port for the API (1–65535) | 11434 |
OLLAMA_HOST |
Hostname or IP shown in startup info and --showkey output |
Auto-detected |
OLLAMA_DEBUG |
Set to 1 to enable verbose debug logging |
(not set) |
OLLAMA_MODELS |
Comma-separated models to pull on first start, e.g. llama3.2:3b,qwen2.5:7b |
(not set) |
OLLAMA_MAX_LOADED_MODELS |
Max models kept loaded in memory simultaneously | (Ollama default) |
OLLAMA_NUM_PARALLEL |
Number of parallel request slots per model | (Ollama default) |
OLLAMA_CONTEXT_LENGTH |
Default context window size in tokens | (Ollama default) |
OLLAMA_DISABLE_USAGE_COUNTS |
Set to 1 to disable anonymous aggregate usage counts. |
(not set) |
Note: In your env file, you may enclose values in single quotes, e.g. VAR='value'. Do not add spaces around =. If you change OLLAMA_PORT, update the -p flag in the docker run command accordingly.
Example using an env file:
cp ollama.env.example ollama.env
# Edit ollama.env and set your values, then:
docker run \
--name ollama \
--restart=always \
-v ollama-data:/var/lib/ollama \
-v ./ollama.env:/ollama.env:ro \
-p 11434:11434/tcp \
-d hwdsl2/ollama-serverOLLAMA_API_KEY_FILE optionally loads the API key from a mounted file. Existing configuration works as before when file inputs are unset.
Use a compatible image and a readable, nonempty file. Leave each matching direct variable unset, including empty assignments in container settings or the mounted env file. See the Compose example and expand the instructions below before changing credential sources.
Existing saved/shared credential copies remain in use; restrict access and include them in your backups.
Setup, rotation and rollback
Setup
The mounted env file keeps its existing precedence. Conflicting sources, an empty file path or an invalid file stop startup before credential/configuration writes.
Note: If the matching direct variable is inherited from -e or Compose environment, remove its assignment and recreate the container. Alternatively, remove any direct assignment from the bind-mounted ollama.env, add the matching unset command (for example, unset OLLAMA_API_KEY) before the _FILE assignment, and restart once the updated file is visible. This command works in the shell-sourced bind-mounted file; Docker --env-file and Compose env_file do not execute shell commands. The workaround leaves the old credential in the container configuration until recreation.
Use a readable, nonempty regular file (a symlink to one is accepted). Paths may contain spaces. Only terminal LF/CRLF sequences are removed; embedded line breaks, lone CR, NUL and other controls are rejected. Bearer tokens may contain ASCII letters, digits and -._~+/, with optional trailing = padding. External permissions and ownership are unchanged.
Choose a compatible published image, or optionally build a local CPU image from this checkout. For a local build, merge the existing configuration with the Compose override:
docker build -t infercrate:secret-files-candidate .
SECRET_FILE_IMAGE=infercrate:secret-files-candidate SECRET_FILE_PATH=/absolute/path/to/api-key \
docker compose -f docker-compose.yml -f docs/examples/compose.secrets.yml configReview the merged configuration before starting only the affected service with the same project, volumes and file arguments. Remove its direct-key assignment first. CUDA deployments must use a compatible CUDA build and their existing CUDA Compose file. Older published images may ignore these inputs; select an image containing this implementation.
Credential storage
Primary keys still reach existing persisted/shared key files and generated configuration. Back up and restrict those copies. File input does not provide encryption or remove secrets from process environments, arguments or upstream state.
The non-secret .api_key.file-source marker makes management helpers prefer the active saved key in file mode, even when exec inherits an older container variable. Startup atomically replaces this marker or clears it when file mode ends.
Rotation and rollback
Rotation is startup-based. After making new contents visible, restart the affected container and refresh credential consumers. Changing the container's environment configuration or mounts requires recreation. Atomic replacement of a bind-mounted host file can leave the old inode mounted; verify visibility and recreate the affected container if needed. Keep persistent volumes and backups. Before downgrading, configure a direct/saved credential supported by the older image and verify protected requests with correct, wrong and missing credentials.
Compatibility
CI covers image builds, authentication and standalone Docker Compose secret mounts for the tested variants. Podman, rootless operation, Podman Compose, Swarm, Kubernetes and GPU acceleration were not tested.
Use docker exec to manage models with the ollama_manage helper script. Models are stored in the Docker volume and persist across container restarts.
List downloaded models:
docker exec ollama ollama_manage --listmodelsPull a model:
# Small, fast models (recommended for getting started)
docker exec ollama ollama_manage --pull llama3.2:3b
docker exec ollama ollama_manage --pull qwen2.5:7b
# Larger models (require more RAM/VRAM)
docker exec ollama ollama_manage --pull mistral:7b
docker exec ollama ollama_manage --pull phi4:14b
docker exec ollama ollama_manage --pull gemma3:12bRemove a model:
docker exec ollama ollama_manage --remove llama3.2:3bShow running models and memory usage:
docker exec ollama ollama_manage --statusUpdate all models (re-pulls latest versions):
docker exec ollama ollama_manage --updateShow the API key:
docker exec ollama ollama_manage --showkeyGet the API key (machine-readable, for use in scripts):
infer_api_key="$(docker exec ollama ollama_manage --getkey)"Pull models on first start using the OLLAMA_MODELS variable in your env file:
OLLAMA_MODELS=llama3.2:3b,qwen2.5:7b
All API requests require a Bearer token. Retrieve the API key first:
infer_api_key="$(docker exec ollama ollama_manage --getkey)"Ollama API:
# List models
curl http://localhost:11434/api/tags \
-H "Authorization: Bearer $infer_api_key"
# Generate (streaming)
curl http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $infer_api_key" \
-d '{"model": "llama3.2:3b", "prompt": "Why is the sky blue?"}'
# Chat completion (streaming)
curl http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $infer_api_key" \
-d '{"model": "llama3.2:3b", "messages": [{"role": "user", "content": "Hello!"}]}'OpenAI-compatible API (Ollama /v1 subset; works with compatible OpenAI SDK and app workflows):
curl http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $infer_api_key" \
-d '{"model": "llama3.2:3b", "messages": [{"role": "user", "content": "Hello!"}]}'Python (OpenAI SDK):
from openai import OpenAI
client = OpenAI(
api_key="<your-api-key>",
base_url="http://localhost:11434/v1",
)
response = client.chat.completions.create(
model="llama3.2:3b",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)All server data is stored in the Docker volume (/var/lib/ollama inside the container):
/var/lib/ollama/
├── models/ # Downloaded model files
├── .api_key # API key (auto-generated, or synced from OLLAMA_API_KEY)
├── .initialized # First-run marker
├── .port # Saved port (used by ollama_manage)
└── .Caddyfile # Generated Caddy config (auth proxy)
Back up the Docker volume to preserve your models and API key.
cp ollama.env.example ollama.env
# Edit ollama.env and set your values, then:
docker compose up -d
docker logs ollamaExample docker-compose.yml (already included):
services:
ollama:
image: hwdsl2/ollama-server
container_name: ollama
restart: always
ports:
- "11434:11434/tcp" # For a host-based reverse proxy, change to "127.0.0.1:11434:11434/tcp"
volumes:
- ollama-data:/var/lib/ollama
- ./ollama.env:/ollama.env:ro
volumes:
ollama-data:
name: ollama-dataNote
For internet-facing deployments, use a reverse proxy to add HTTPS. Also change "11434:11434/tcp" to "127.0.0.1:11434:11434/tcp" in docker-compose.yml, to prevent direct access to the unencrypted port.
Use docker-compose.cuda.yml to run with NVIDIA GPU support:
docker compose -f docker-compose.cuda.yml up -dRequirements: NVIDIA GPU, NVIDIA driver 575.57.08+ (Linux) or 576.57+ (Windows), and the NVIDIA Container Toolkit installed on the host. The :cuda image is linux/amd64 only.
For internet-facing deployments, place a reverse proxy in front of Ollama to handle HTTPS termination. The server works without HTTPS on a local or trusted network, but HTTPS is recommended when the API endpoint is exposed to the internet.
Use one of the following addresses to reach the Ollama container from your reverse proxy:
ollama:11434— if your reverse proxy runs as a container in the same Docker network as Ollama (e.g. defined in the samedocker-compose.yml).127.0.0.1:11434— if your reverse proxy runs on the host and port11434is published (the defaultdocker-compose.ymlpublishes it).
Note: The Authorization: Bearer header passes through reverse proxies automatically — no special configuration needed.
Example with Caddy (Docker image) (automatic TLS via Let's Encrypt, reverse proxy in the same Docker network):
Caddyfile:
ollama.example.com {
reverse_proxy ollama:11434
}
Example with nginx (reverse proxy on the host):
server {
listen 443 ssl;
server_name ollama.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:11434;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1; # required for streaming responses
proxy_read_timeout 300s;
proxy_buffering off;
}
}After setting up a reverse proxy, set OLLAMA_HOST=ollama.example.com in your env file so that the correct endpoint URL is shown in the startup logs and ollama_manage --showkey output.
To update the Docker image and container:
docker pull hwdsl2/ollama-server
docker rm -f ollama
# Then re-run the docker run command from Quick start with the same volume.Your downloaded models are preserved in the ollama-data volume.
Ollama can be used as the local LLM service in a broader self-hosted AI setup.
For full and lightweight Docker Compose stacks, manual docker run examples, and voice/RAG/MCP pipeline examples with SpeakCrate, EmbedCrate, GatewayCrate, InferCrate, ParseCrate, and UplinkCrate, see Self-Hosted AI Stack.
Related AI services:
- Voice: ScribeCrate, SpeakCrate
- Documents & search: ParseCrate, EmbedCrate
- Models & gateways: GatewayCrate, UplinkCrate
Connect Ollama to LiteLLM:
# In docker-litellm, add Ollama as a model provider:
docker exec litellm litellm_manage \
--addmodel ollama/llama3.2:3b \
--base-url http://ollama:11434This image uses public GitHub release asset download counts for anonymous, aggregate usage counts. Counts are approximate and are not unique users or active installs. The image does not send a telemetry payload or use a private collector. It only attempts the best-effort count after the server starts successfully with a mounted /var/lib/ollama volume, and again when that persistent install first runs a different image build. To opt out, set OLLAMA_DISABLE_USAGE_COUNTS=1.
- Base image:
debian:trixie-slimfor:latest;nvidia/cudafor:cuda - Image size: ~80MB (CPU) / ~1.8GB (CUDA)
- Ollama: latest release, installed as a static binary
- Auth proxy: Caddy (always active, enforces Bearer token auth)
- Data directory:
/var/lib/ollama(Docker volume) - Model storage:
/var/lib/ollama/modelsinside the volume - Ollama API:
http://localhost:11434(or your configured port) - OpenAI-compatible API:
http://localhost:11434/v1
Note: The software components inside the pre-built image (such as Ollama, Caddy, and their dependencies) are under the respective licenses chosen by their respective copyright holders. As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
Copyright (C) 2026 Lin Song
This work is licensed under the MIT License.
Ollama is Copyright (C) 2023 Ollama, and is distributed under the MIT License.
Caddy is Copyright (C) 2015 Matthew Holt and The Caddy Authors, and is distributed under the Apache License 2.0.
This project is an independent Docker setup for Ollama and is not affiliated with, endorsed by, or sponsored by Ollama.