Skip to content

Deploying a Nagios App

Introduction

Nagios is a widely used open-source monitoring platform for hosts, services, and network devices. Deploying Nagios with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for configs and state—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample checks, and production tips.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your Nagios Dockerfile (GitHub is the only supported git source)
  • Monitoring targets reachable from your Klutch.sh app
  • Optional SMTP credentials for alerts

For onboarding, see the Quick Start.


Architecture and ports

  • Nagios web UI typically runs on Apache; set the internal container port to 8080 (mapped from the Apache port) and choose HTTP traffic.
  • Persistent storage is required for configuration, state retention, and logs.

Repository layout

nagios/
├── Dockerfile # Must be at repo root for auto-detection
└── README.md

Keep secrets (web admin credentials, SMTP passwords) out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
docker build -t nagios-local .
docker run -p 8080:8080 -e NAGIOSADMIN_USER=admin -e NAGIOSADMIN_PASS=changeme nagios-local

Dockerfile for Nagios (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM jasonrivers/nagios:latest
# Map Apache/Nagios UI to 8080 inside the container
ENV APACHE_HTTP_PORT_NUMBER=8080 \
NAGIOSADMIN_USER=admin \
NAGIOSADMIN_PASS=changeme
EXPOSE 8080
CMD ["/usr/local/bin/start_nagios"]

Notes:

  • Pin the image tag (e.g., jasonrivers/nagios:latest-ubuntu) for stability and upgrade intentionally.
  • You can COPY custom configs or plugins into /opt/nagios/etc and /opt/Custom-Nagios-Plugins if needed.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • APACHE_HTTP_PORT_NUMBER=8080
  • NAGIOSADMIN_USER=<admin-user>
  • NAGIOSADMIN_PASS=<strong-password>
  • Optional email: SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM

If you deploy without the Dockerfile and need Nixpacks overrides (not typical for this image):

  • NIXPACKS_START_CMD=/usr/local/bin/start_nagios

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /opt/nagios/etc — Nagios configuration files.
  • /opt/nagios/var — state retention, logs, and status data.
  • /opt/Custom-Nagios-Plugins — optional custom plugin directory.

Ensure these directories are writable.


Deploy Nagios on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 8080.
  4. Add the environment variables above, including admin credentials and SMTP settings.
  5. Attach persistent volumes for /opt/nagios/etc, /opt/nagios/var, and optional /opt/Custom-Nagios-Plugins with sizes that fit your config and log retention needs.
  6. Deploy. Access the Nagios UI at https://example-app.klutch.sh using the admin credentials.

Sample checks and usage

Verify the web UI is reachable:

Terminal window
curl -I https://example-app.klutch.sh

Add a simple host check (place in your persisted config):

define host {
use linux-server
host_name example-host
address 8.8.8.8
}
define service {
use generic-service
host_name example-host
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

Reload Nagios via the UI or a one-off exec if needed.


Health checks and production tips

  • Add an HTTP probe to / on port 8080 for readiness.
  • Enforce HTTPS at the edge; forward internally to port 8080.
  • Keep admin and SMTP credentials in Klutch.sh secrets; rotate them regularly.
  • Monitor volume usage for /opt/nagios/var; resize before it fills.
  • Pin image versions and back up /opt/nagios/etc before upgrades.

Nagios on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 8080 configured, and configs persisted, you can deliver reliable monitoring without extra YAML or workflow overhead.