Skip to content

Commit 7fa9842

Browse files
committed
update docker compose and readme
1 parent c63e6ec commit 7fa9842

File tree

2 files changed

+191
-4
lines changed

2 files changed

+191
-4
lines changed

README.md

Lines changed: 188 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,188 @@
1-
# ollama-api-server
2-
Expose a local ollama api behind defined api keys - easy setup with docker!
1+
# 🦙 Ollama API Server
2+
3+
Secure your local Ollama instance with API keys and enhanced features - simple setup with Docker!
4+
5+
<a href="https://www.buymeacoffee.com/gitmotion" target="_blank" rel="noopener noreferrer">
6+
<img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy me a coffee" width="150px" />
7+
</a>
8+
9+
## 📑 Table of Contents
10+
- [⭐ Features](#⭐-features)
11+
- [🚀 Quick Start](#🚀-quick-start)
12+
- [📖 Detailed Setup](#📖-detailed-setup)
13+
- [🐳 Docker Setup (Recommended)](#🐳-docker-setup-recommended)
14+
- [📂 Docker Image](#📂-docker-image)
15+
- [📄 Docker Compose Configuration](#📄-docker-compose-configuration)
16+
- [💻 Local Setup](#💻-local-setup)
17+
- [⚙️ Configuration](#⚙️-configuration)
18+
- [🔌 API Endpoints](#🔌-api-endpoints)
19+
- [🔐 Authentication](#🔐-authentication)
20+
21+
## ⭐ Features
22+
- 🔑 API Key Authentication
23+
- 🔄 CORS Support
24+
- 🚀 Connection Pooling
25+
- 🌊 Streaming Support
26+
- 🐳 Easy Docker Setup
27+
- 🔌 All Ollama API Endpoints Supported
28+
29+
## 🚀 Quick Start
30+
31+
```bash
32+
# 1. Create a .env file with your API keys
33+
echo "API_KEYS=your-secret-key-1,your-secret-key-2" > .env
34+
35+
# 2. Start the server with Docker
36+
docker compose up -d
37+
```
38+
39+
That's it! Your secure Ollama API server is running on port 7777.
40+
41+
## 📖 Detailed Setup
42+
43+
### 🐳 Docker Setup (Recommended)
44+
45+
### 📂 Docker Image
46+
47+
The official Docker image is available on Docker Hub and GitHub Container Registry:
48+
49+
```bash
50+
# Docker Hub
51+
docker pull gitmotion/ollama-api-server:latest
52+
53+
# GitHub Container Registry
54+
docker pull ghcr.io/gitmotion/ollama-api-server:latest
55+
```
56+
57+
1. Clone the repository:
58+
```bash
59+
git clone https://github.com/gitmotion/ollama-api-server.git
60+
cd ollama-api-server
61+
```
62+
63+
2. Create a .env file:
64+
```bash
65+
cp .env.example .env
66+
```
67+
68+
3. Edit the .env file with your preferred settings:
69+
```env
70+
PORT_EXTERNAL=7777
71+
OLLAMA_BASE_URL=http://localhost:11434
72+
CORS_ORIGIN=*
73+
API_KEYS=your-secret-key-1,your-secret-key-2
74+
```
75+
76+
4. Start the server:
77+
```bash
78+
docker compose up -d
79+
```
80+
81+
### 📄 Docker Compose Configuration
82+
83+
The server uses the following `docker-compose.yml` configuration:
84+
85+
```yaml
86+
services:
87+
api:
88+
image: gitmotion/ollama-api-server:latest
89+
container_name: ollama-api-server
90+
restart: unless-stopped
91+
ports:
92+
- "${PORT_EXTERNAL:-7777}:7777"
93+
environment:
94+
- PORT=7777
95+
- OLLAMA_BASE_URL=http://internal-ip-where-ollama-installed:11434 # must serve your ollama server with 0.0.0.0
96+
- CORS_ORIGIN=*
97+
- API_KEYS=${API_KEYS:-default-key-1,default-key-2}
98+
```
99+
100+
This configuration:
101+
- Uses the official Docker image
102+
- Maps the container's port 7777 to your host's port (configurable via PORT_EXTERNAL)
103+
- Sets up the required environment variables
104+
- Provides default API keys if none are specified
105+
106+
You can customize the configuration by:
107+
1. Changing the external port (PORT_EXTERNAL in .env)
108+
2. Setting your API keys (API_KEYS in .env)
109+
3. Modifying the Ollama base URL if needed
110+
4. Adjusting CORS settings for your environment
111+
112+
### 💻 Local Setup
113+
114+
1. Clone the repository:
115+
```bash
116+
git clone https://github.com/gitmotion/ollama-api-server.git
117+
cd ollama-api-server
118+
```
119+
120+
2. Install dependencies:
121+
```bash
122+
npm install
123+
```
124+
125+
3. Create and configure .env file:
126+
```bash
127+
cp .env.example .env
128+
# Edit .env with your settings
129+
```
130+
131+
4. Build and start the server:
132+
```bash
133+
npm run build
134+
npm start
135+
```
136+
137+
## ⚙️ Configuration
138+
139+
The server can be configured using environment variables:
140+
141+
| Variable | Description | Default |
142+
|----------|-------------|---------|
143+
| PORT | Server port | 7777 |
144+
| OLLAMA_BASE_URL | URL of your Ollama instance | http://localhost:11434 |
145+
| CORS_ORIGIN | CORS origin setting | * |
146+
| API_KEYS | Comma-separated list of valid API keys | default-key-1,default-key-2 |
147+
148+
## 🔌 API Endpoints
149+
150+
All Ollama API endpoints are supported with authentication:
151+
152+
- `POST /api/chat` - Chat completion
153+
- `POST /api/generate` - Text generation
154+
- `POST /api/embeddings` - Generate embeddings
155+
- `GET /api/tags` - List available models
156+
- `POST /api/show` - Show model details
157+
- `POST /api/pull` - Pull a model
158+
- `DELETE /api/delete` - Delete a model
159+
- `POST /api/copy` - Copy a model
160+
- `GET /api/version` - Get Ollama version
161+
- `GET /health` - Health check endpoint
162+
163+
## 🔐 Authentication
164+
165+
Include your API key in requests using one of these methods:
166+
167+
1. X-API-Key header:
168+
```bash
169+
curl -H "x-api-key: your-api-key" http://localhost:7777/api/tags
170+
```
171+
172+
2. Authorization header:
173+
```bash
174+
curl -H "Authorization: Bearer your-api-key" http://localhost:7777/api/tags
175+
```
176+
177+
3. Request body:
178+
```bash
179+
curl -X POST -H "Content-Type: application/json" \
180+
-d '{"apiKey": "your-api-key"}' \
181+
http://localhost:7777/api/tags
182+
```
183+
184+
For the latest version and updates, check out our GitHub repository.
185+
186+
___
187+
188+
Made with ❤️ by [gitmotion](https://github.com/gitmotion)

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ services:
22
api:
33
# image: gitmotion/ollama-api-server:latest
44
build: .
5-
container_name: ollama-api
5+
container_name: ollama-api-server
6+
restart: unless-stopped
67
ports:
78
- "${PORT_EXTERNAL:-7777}:7777"
89
environment:
910
- PORT=7777
10-
- OLLAMA_BASE_URL=http://127.0.0.1:11434
11+
- OLLAMA_BASE_URL=http://internal-ip-where-ollama-installed:11434 # must serve your ollama server with 0.0.0.0
1112
- CORS_ORIGIN=*
1213
- API_KEYS=${API_KEYS:-default-key-1,default-key-2}

0 commit comments

Comments
 (0)