Laravel

Nightwatch

Run the Laravel Nightwatch agent as its own container with php artisan nightwatch:agent. Your web and worker containers send their data to the agent over TCP port 2407.

Install and configure the Nightwatch package first, following the Nightwatch start guide.

Compose example

compose.yml
services:
  app:
    image: my-org/my-app:1.0.0
    ports:
      - "80:8080"
    environment:
      NIGHTWATCH_INGEST_URI: "nightwatch:2407"

  nightwatch:
    image: my-org/my-app:1.0.0
    command: ["php", "artisan", "nightwatch:agent", "--listen-on=0.0.0.0:2407"]
    stop_signal: SIGTERM
    healthcheck:
      test: ["CMD", "healthcheck-nightwatch"]
      start_period: 10s

stop_signal and the health check are required on every worker. Running workers explains why.

Connect your app to the agent

By default the app sends to 127.0.0.1:2407 and the agent listens there, which only works inside one container. With a separate agent container:

  • Set NIGHTWATCH_INGEST_URI to the agent's service name and port (nightwatch:2407) on every container that runs your app, including queue and scheduler workers.
  • Start the agent with --listen-on=0.0.0.0:2407 so other containers can reach it.
  • Set the same NIGHTWATCH_TOKEN on the app and the agent.
  • Don't publish port 2407. Only your app containers should reach the agent.

Nightwatch's Docker guide covers sidecar and Kubernetes setups.

Health check

healthcheck-nightwatch runs php artisan nightwatch:status to check the agent's status. It boots your application on every check.