Skip to content

Commit 2a792f7

Browse files
committed
fix problematic missing env
1 parent 1dafad5 commit 2a792f7

File tree

3 files changed

+225
-10
lines changed

3 files changed

+225
-10
lines changed

README.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,82 @@ Visit `http://localhost:5000`
119119

120120
### Using Pre-built Image (Recommended)
121121

122+
**Important:** You must mount a configuration file for the container to work properly!
123+
122124
```bash
123-
# Pull the latest image
125+
# 1. Create a config.yaml file on your host
126+
cat > config.yaml << 'EOF'
127+
kea:
128+
control_agent_url: "https://your-kea-server:8000"
129+
username: "admin"
130+
password: "your-password"
131+
default_subnet_id: 1
132+
133+
app:
134+
host: "0.0.0.0"
135+
port: 5000
136+
debug: false
137+
138+
logging:
139+
level: "INFO"
140+
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
141+
EOF
142+
143+
# 2. Pull the latest image
124144
docker pull awkto/kea-gui-reservations:latest
125145

126-
# Run with your config
146+
# 3. Run with your config mounted
127147
docker run -d \
128148
--name kea-gui \
129149
-p 5000:5000 \
130150
-v $(pwd)/config.yaml:/app/config/config.yaml:ro \
131151
awkto/kea-gui-reservations:latest
152+
153+
# 4. Check logs to verify config was loaded
154+
docker logs kea-gui | head -20
155+
# Should see: "✅ Loaded configuration from /app/config/config.yaml"
132156
```
133157

134-
### Building from Source
158+
**⚠️ Common Mistake:** Forgetting to mount the config file will cause the container to use default settings (localhost), which will fail!
159+
160+
### Using Docker Compose (Easiest)
135161

136162
```bash
137-
docker build -t kea-gui .
138-
docker run -p 5000:5000 -v $(pwd)/config.yaml:/app/config.yaml kea-gui
163+
# 1. Clone the repository or create these files:
164+
# - docker-compose.yml
165+
# - config.yaml
166+
167+
# 2. Edit config.yaml with your KEA server details
168+
169+
# 3. Start the container
170+
docker-compose up -d
171+
172+
# 4. View logs
173+
docker-compose logs -f
139174
```
140175

141-
### Using Docker Compose
176+
### Verifying Configuration
177+
178+
After starting the container, verify the config was loaded:
142179

143180
```bash
144-
docker-compose up -d
181+
# Check config file exists in container
182+
docker exec kea-gui cat /app/config/config.yaml
183+
184+
# Check via API
185+
curl http://localhost:5000/api/config | jq '.config.kea.control_agent_url'
186+
187+
# Check health
188+
curl http://localhost:5000/api/health
189+
```
190+
191+
**Troubleshooting:** If you see errors connecting to localhost when you configured a different server, see [DOCKER_CONFIG_TROUBLESHOOTING.md](DOCKER_CONFIG_TROUBLESHOOTING.md)
192+
193+
### Building from Source
194+
195+
```bash
196+
docker build -t kea-gui .
197+
docker run -d -p 5000:5000 -v $(pwd)/config.yaml:/app/config/config.yaml:ro kea-gui
145198
```
146199

147200
## API Endpoints

app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@
4747
config[key].update(loaded_config[key])
4848
else:
4949
config[key] = loaded_config[key]
50-
logger_msg = f"Loaded configuration from {config_path}"
50+
logger_msg = f"✅ Loaded configuration from {config_path}"
51+
logger_msg += f"\n KEA URL: {config['kea']['control_agent_url']}"
5152
except Exception as e:
52-
logger_msg = f"Error loading config, using defaults: {e}"
53+
logger_msg = f"Error loading config from {config_path}, using defaults: {e}"
5354
else:
54-
logger_msg = f"No config file found at {config_path}, using defaults"
55+
logger_msg = f"⚠️ No config file found at {config_path}, using defaults"
56+
logger_msg += f"\n Default KEA URL: {config['kea']['control_agent_url']}"
57+
logger_msg += f"\n 💡 Tip: Mount your config.yaml to /app/config/config.yaml in Docker"
5558

5659
# Setup logging
5760
logging.basicConfig(

diagnose-docker.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
# KEA GUI Container Diagnostics Script
3+
# Run this to diagnose configuration issues
4+
5+
CONTAINER_NAME="${1:-kea-gui}"
6+
7+
echo "╔════════════════════════════════════════════════════════════════╗"
8+
echo "║ KEA GUI Container Diagnostics ║"
9+
echo "╚════════════════════════════════════════════════════════════════╝"
10+
echo ""
11+
echo "Container: $CONTAINER_NAME"
12+
echo ""
13+
14+
# Check if container exists
15+
if ! docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
16+
echo "❌ Container '$CONTAINER_NAME' not found!"
17+
echo ""
18+
echo "Available containers:"
19+
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'
20+
exit 1
21+
fi
22+
23+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
24+
echo "1. Container Status"
25+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
26+
docker ps -a --filter "name=^${CONTAINER_NAME}$" --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
27+
echo ""
28+
29+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
30+
echo "2. Config File on Host"
31+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
32+
if [ -f "config.yaml" ]; then
33+
echo "✅ config.yaml exists in current directory"
34+
ls -lh config.yaml
35+
echo ""
36+
echo "KEA URL configured:"
37+
grep "control_agent_url" config.yaml || echo "⚠️ control_agent_url not found"
38+
else
39+
echo "❌ config.yaml NOT FOUND in current directory!"
40+
echo " Create one or cd to the directory containing config.yaml"
41+
fi
42+
echo ""
43+
44+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
45+
echo "3. Container Environment Variables"
46+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
47+
docker exec "$CONTAINER_NAME" env | grep -E "CONFIG|PYTHON" 2>&1 || echo "❌ Cannot access container environment"
48+
echo ""
49+
50+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
51+
echo "4. Config Directory in Container"
52+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
53+
docker exec "$CONTAINER_NAME" ls -la /app/config/ 2>&1 || echo "❌ /app/config/ directory not found or not accessible"
54+
echo ""
55+
56+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
57+
echo "5. Config File Content in Container"
58+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
59+
if docker exec "$CONTAINER_NAME" test -f /app/config/config.yaml 2>/dev/null; then
60+
echo "✅ Config file exists in container"
61+
echo ""
62+
docker exec "$CONTAINER_NAME" cat /app/config/config.yaml 2>&1 | head -20
63+
else
64+
echo "❌ Config file NOT FOUND at /app/config/config.yaml"
65+
echo " This means the volume mount is missing or incorrect!"
66+
echo ""
67+
echo " Fix: Stop container and run with:"
68+
echo " docker run -d --name $CONTAINER_NAME -p 5000:5000 \\"
69+
echo " -v \$(pwd)/config.yaml:/app/config/config.yaml:ro \\"
70+
echo " awkto/kea-gui-reservations:latest"
71+
fi
72+
echo ""
73+
74+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
75+
echo "6. API Config Endpoint Check"
76+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
77+
RESPONSE=$(curl -s http://localhost:5000/api/config 2>&1)
78+
if echo "$RESPONSE" | grep -q "control_agent_url"; then
79+
KEA_URL=$(echo "$RESPONSE" | grep -o '"control_agent_url":"[^"]*"' | cut -d'"' -f4)
80+
echo "✅ API is responding"
81+
echo " Configured KEA URL: $KEA_URL"
82+
83+
if [[ "$KEA_URL" == *"localhost"* ]] || [[ "$KEA_URL" == *"127.0.0.1"* ]]; then
84+
echo " ⚠️ WARNING: Using localhost - config file may not be mounted!"
85+
fi
86+
else
87+
echo "❌ Cannot reach API or invalid response"
88+
echo "Response: $RESPONSE"
89+
fi
90+
echo ""
91+
92+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
93+
echo "7. Health Check"
94+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
95+
curl -s http://localhost:5000/api/health 2>&1 | python3 -m json.tool 2>/dev/null || echo "❌ Health check failed or invalid JSON"
96+
echo ""
97+
98+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
99+
echo "8. Recent Container Logs (last 30 lines)"
100+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
101+
docker logs --tail 30 "$CONTAINER_NAME" 2>&1
102+
echo ""
103+
104+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
105+
echo "9. Volume Mounts"
106+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
107+
docker inspect "$CONTAINER_NAME" --format='{{range .Mounts}}{{.Source}} -> {{.Destination}} ({{.Mode}}){{"\n"}}{{end}}' 2>&1
108+
echo ""
109+
110+
echo "╔════════════════════════════════════════════════════════════════╗"
111+
echo "║ Summary ║"
112+
echo "╚════════════════════════════════════════════════════════════════╝"
113+
echo ""
114+
115+
# Determine issues
116+
HAS_ISSUES=false
117+
118+
# Check if config file is mounted
119+
if ! docker exec "$CONTAINER_NAME" test -f /app/config/config.yaml 2>/dev/null; then
120+
echo "❌ ISSUE: Config file not mounted in container"
121+
HAS_ISSUES=true
122+
fi
123+
124+
# Check if using localhost
125+
KEA_URL=$(curl -s http://localhost:5000/api/config 2>/dev/null | grep -o '"control_agent_url":"[^"]*"' | cut -d'"' -f4)
126+
if [[ "$KEA_URL" == *"localhost"* ]] || [[ "$KEA_URL" == *"127.0.0.1"* ]]; then
127+
echo "⚠️ WARNING: Application is configured to use localhost"
128+
echo " This usually means the config file is not properly mounted"
129+
HAS_ISSUES=true
130+
fi
131+
132+
if [ "$HAS_ISSUES" = false ]; then
133+
echo "✅ No obvious issues detected!"
134+
echo ""
135+
echo "If you're still having problems, check:"
136+
echo " - KEA server is reachable from this container"
137+
echo " - KEA Control Agent is running on the configured port"
138+
echo " - Required hook libraries (lease_cmds, host_cmds) are loaded"
139+
else
140+
echo ""
141+
echo "📋 Recommended Actions:"
142+
echo ""
143+
echo "1. Stop the container:"
144+
echo " docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME"
145+
echo ""
146+
echo "2. Ensure config.yaml exists in current directory"
147+
echo ""
148+
echo "3. Run with proper volume mount:"
149+
echo " docker run -d --name $CONTAINER_NAME \\"
150+
echo " -p 5000:5000 \\"
151+
echo " -v \$(pwd)/config.yaml:/app/config/config.yaml:ro \\"
152+
echo " awkto/kea-gui-reservations:latest"
153+
echo ""
154+
echo " OR use docker-compose:"
155+
echo " docker-compose up -d"
156+
fi
157+
158+
echo ""
159+
echo "For more help, see: DOCKER_CONFIG_TROUBLESHOOTING.md"

0 commit comments

Comments
 (0)