Fix container health checks and expose services externally

- Replace artisan-based health check with php-fpm process check
- Change port bindings from localhost to all interfaces (0.0.0.0)
- Add restart policies to ensure service availability
- Extend API startup period from 60s to 90s
- Add comprehensive restart instructions and troubleshooting guide

This allows external access to the application and improves container
reliability by fixing health check failures.
This commit is contained in:
Matt 2025-06-05 18:00:12 +02:00
parent 878d72b785
commit f04e93ddb4
2 changed files with 50 additions and 4 deletions

43
RESTART_INSTRUCTIONS.md Normal file
View File

@ -0,0 +1,43 @@
# How to Restart OpnForm Containers
Since you're using a web-based Docker management interface, follow these steps:
## 1. Stop All Containers
In your Docker management interface:
- Select all OpnForm containers
- Click "Stop" or use the stop button
- Wait for all containers to stop
## 2. Start Containers in Correct Order
Start the containers in this order:
1. **opnform-db** - Wait until healthy
2. **opnform-redis** - Wait until healthy
3. **opnform-api** - Wait until it shows as running
4. **opnform-api-nginx** - This should now start successfully
5. **opnform-api-worker** - Start this
6. **opnform-api-scheduler** - Start this
7. **opnform-client** - Start this last
## 3. Verify Services
After all containers are running:
- Check that `opnform-api-nginx` is healthy (not "starting")
- Access the UI at: http://YOUR-SERVER-IP:7655
- API should be available at: http://YOUR-SERVER-IP:7654
## What Changed
1. **Fixed PHP-FPM health check** - Changed from running artisan command to checking if php-fpm process exists
2. **Added restart policies** - Containers will restart unless manually stopped
3. **Changed port bindings** - From 127.0.0.1 (localhost only) to 0.0.0.0 (accessible from any IP)
4. **Extended start period** - Gave API container more time to start before health checks
## Troubleshooting
If api-nginx is still unhealthy:
1. Check logs of opnform-api container
2. Verify PHP-FPM is running: Look for php-fpm processes in the api container
3. Check api-nginx logs for connection errors
## Security Note
The services are now exposed on all network interfaces. For production:
- Use a firewall to restrict access
- Configure your host nginx with SSL
- Or revert to localhost binding after testing

View File

@ -26,11 +26,12 @@ services:
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "php /usr/share/nginx/html/artisan about || exit 1"]
test: ["CMD-SHELL", "pgrep php-fpm > /dev/null || exit 1"]
interval: 30s
timeout: 15s
retries: 3
start_period: 60s
start_period: 90s
restart: unless-stopped
api-nginx:
image: nginx:alpine
@ -39,7 +40,7 @@ services:
- ./docker/api-nginx.conf:/etc/nginx/nginx.conf:ro
- opnform_storage:/usr/share/nginx/html/storage:ro
ports:
- "127.0.0.1:7654:80" # API on port 7654
- "0.0.0.0:7654:80" # API on port 7654 - accessible from any IP
depends_on:
- api
healthcheck:
@ -47,6 +48,7 @@ services:
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
api-worker:
image: jhumanj/opnform-api:latest
@ -120,7 +122,7 @@ services:
image: jhumanj/opnform-client:latest
container_name: opnform-client
ports:
- "127.0.0.1:7655:3000" # UI on port 7655
- "0.0.0.0:7655:3000" # UI on port 7655 - accessible from any IP
env_file:
- ./client/.env
healthcheck:
@ -129,6 +131,7 @@ services:
timeout: 10s
retries: 3
start_period: 45s
restart: unless-stopped
redis:
image: redis:7