-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathstart-docker.sh
More file actions
executable file
·183 lines (166 loc) · 5.68 KB
/
Copy pathstart-docker.sh
File metadata and controls
executable file
·183 lines (166 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# LocalGPT Docker Startup Script
# This script provides easy options for running LocalGPT in Docker
set -e
echo "🐳 LocalGPT Docker Deployment"
echo "============================"
# Non-interactive mode: never prompt. Enable with -y/--yes or NONINTERACTIVE=1.
ASSUME_YES="${NONINTERACTIVE:-}"
ARGS=()
for arg in "$@"; do
case "$arg" in
-y|--yes|--assume-yes)
ASSUME_YES=1
;;
*)
ARGS+=("$arg")
;;
esac
done
set -- "${ARGS[@]}"
# Function to check if local Ollama is running
check_local_ollama() {
if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
echo "✅ Local Ollama detected on port 11434"
return 0
else
echo "❌ No local Ollama detected on port 11434"
return 1
fi
}
# Function to start with local Ollama
start_with_local_ollama() {
echo "🚀 Starting LocalGPT containers (using local Ollama)..."
echo "📝 Note: Make sure your local Ollama is running on port 11434"
# Use the docker.env file for configuration
docker compose --env-file docker.env up --build -d
echo ""
echo "🎉 LocalGPT is starting up!"
echo "📱 Frontend: http://localhost:3000"
echo "🔧 Backend API: http://localhost:8000"
echo "🧠 RAG API: http://localhost:8001"
echo "🤖 Ollama: http://localhost:11434 (local)"
echo ""
echo "📊 Check container status: docker compose ps"
echo "📝 View logs: docker compose logs -f"
echo "🛑 Stop services: docker compose down"
}
# Function to start with containerized Ollama
start_with_container_ollama() {
echo "🚀 Starting LocalGPT containers (including Ollama container)..."
# Set environment variable for containerized Ollama.
# The shell environment takes precedence over --env-file, so this wins over docker.env.
export OLLAMA_HOST=http://ollama:11434
# Start all services including Ollama
docker compose --env-file docker.env --profile with-ollama up --build -d
echo ""
echo "🎉 LocalGPT is starting up!"
echo "📱 Frontend: http://localhost:3000"
echo "🔧 Backend API: http://localhost:8000"
echo "🧠 RAG API: http://localhost:8001"
echo "🤖 Ollama: http://localhost:11434 (containerized)"
echo ""
echo "⏳ Note: First startup may take longer as Ollama container initializes"
echo "📊 Check container status: docker compose --profile with-ollama ps"
echo "📝 View logs: docker compose --profile with-ollama logs -f"
echo "🛑 Stop services: docker compose --profile with-ollama down"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [option] [-y|--yes]"
echo ""
echo "Options:"
echo " local - Use local Ollama instance (default)"
echo " container - Use containerized Ollama"
echo " stop - Stop all containers"
echo " logs - Show container logs"
echo " status - Show container status"
echo " help - Show this help message"
echo ""
echo "Flags:"
echo " -y, --yes - Never prompt; fall back to containerized Ollama when no local"
echo " Ollama is detected. Also enabled with NONINTERACTIVE=1."
echo ""
echo "Examples:"
echo " $0 local # Use local Ollama (recommended)"
echo " $0 container # Use containerized Ollama"
echo " $0 local -y # Scripted/CI use - no prompts"
echo " $0 stop # Stop all services"
}
# Function to stop containers
stop_containers() {
echo "🛑 Stopping LocalGPT containers..."
docker compose down
docker compose --profile with-ollama down 2>/dev/null || true
echo "✅ All containers stopped"
}
# Function to show logs
show_logs() {
echo "📝 Showing container logs (Ctrl+C to exit)..."
if docker compose ps | grep -q "rag-ollama"; then
docker compose --profile with-ollama logs -f
else
docker compose logs -f
fi
}
# Function to show status
show_status() {
echo "📊 Container Status:"
docker compose ps
echo ""
echo "🐳 All Docker containers:"
docker ps | grep -E "(rag-|CONTAINER)" || echo "No LocalGPT containers running"
}
# Main script logic
case "${1:-local}" in
"local")
if check_local_ollama; then
start_with_local_ollama
else
echo ""
echo "⚠️ No local Ollama detected. Options:"
echo "1. Start local Ollama: 'ollama serve'"
echo "2. Use containerized Ollama: '$0 container'"
echo ""
if [ -n "$ASSUME_YES" ]; then
echo "▶️ Non-interactive mode: starting containerized Ollama"
start_with_container_ollama
elif [ -t 0 ]; then
read -p "Start with containerized Ollama instead? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
start_with_container_ollama
else
echo "❌ Cancelled. Please start local Ollama or use '$0 container'"
exit 1
fi
else
echo "❌ No TTY for the confirmation prompt."
echo " Re-run with '$0 local --yes' (or NONINTERACTIVE=1 $0) to use containerized Ollama,"
echo " or '$0 container' to select it explicitly."
exit 1
fi
fi
;;
"container")
start_with_container_ollama
;;
"stop")
stop_containers
;;
"logs")
show_logs
;;
"status")
show_status
;;
"help"|"-h"|"--help")
show_usage
;;
*)
echo "❌ Unknown option: $1"
echo ""
show_usage
exit 1
;;
esac