Laravel
Nightwatch
Laravel Nightwatch with Docker
Run Laravel Nightwatch by passing the Artisan command as the container's command. Nightwatch is Laravel's observability platform for monitoring application performance, errors, and queries in real-time.
Before using Nightwatch with Docker, follow the Laravel Nightwatch setup instructions to install and configure the Nightwatch package in your Laravel application.
Docker Compose example
This example runs Nightwatch as a separate container using the same image as your web service.
Key points:
- Use the same image for both your web and Nightwatch services
- Set
SIGTERMas the stop signal for graceful shutdown (especially forfpm-apacheandfpm-nginx) - Include a health check to monitor Nightwatch status
compose.yml
services:
php:
image: my/laravel-app
nightwatch:
image: my/laravel-app
command: ["php", "/var/www/html/artisan", "nightwatch:agent"]
stop_signal: SIGTERM
healthcheck:
test: ["CMD", "healthcheck-nightwatch"]
start_period: 10s
How the health check works
The healthcheck-nightwatch command runs php artisan nightwatch:status to verify that the Nightwatch agent is running and connected. Docker uses this to determine container health and can automatically restart unhealthy containers.
Advanced configuration
Graceful shutdown: The SIGTERM signal ensures the Nightwatch agent finishes processing current events before stopping. This is especially important for fpm-apache and fpm-nginx images.
Multiple processes in one container: If you're running
fpm-nginx or fpm-apache and you'd like to have everything in a single container, you can write your own S6 Overlay service script to properly manage multiple processes in a single container. Learn more about about this in our Using S6 Overlay guide.