Skip to main content

Installing Nagios4 with Docker

Cheung Chau, Hong Kong

Installation

Start by pulling the Nagios Core 4.4.5 running on Ubuntu 16.04 LTS with NagiosGraph & NRPE:

docker pull jasonrivers/nagios:latest

Test Run

Run with the example configuration with the following:

docker run --name nagios4 -p 0.0.0.0:8888:80 jasonrivers/nagios:latest

Credentials

Open the Nagios Webui on port 8888. The default credentials for the web interface is nagiosadmin / nagios.

You can copy the sample content of the following directories inside the docker container to you host system docker exec -ti nagios4 /bin/bash - e.g. to the /opt directory:

  • /opt/nagios/etc/
  • /opt/nagios/var/
  • /opt/Custom-Nagios-Plugins
  • /opt/nagiosgraph/var
  • /opt/nagiosgraph/etc

Modify the configuration according to your needs and mount it back into the container:

docker run --name nagios4  \
-v /opt/nagios/etc/:/opt/nagios/etc/ \
-v /opt/nagios/var:/opt/nagios/var/ \
-v /opt/Custom-Nagios-Plugins:/opt/Custom-Nagios-Plugins \
-v /opt/nagiosgraph/var:/opt/nagiosgraph/var \
-v /opt/nagiosgraph/etc:/opt/nagiosgraph/etc \
-p 0.0.0.0:8888:80 jasonrivers/nagios:latest

I only copied the content of /opt/nagios/etc/ for now:

find /opt/nagios/etc -printf "%P\n"

conf.d
resource.cfg
nagios.cfg
objects
objects/switch.cfg
objects/timeperiods.cfg
objects/templates.cfg
objects/localhost.cfg
objects/contacts.cfg
objects/printer.cfg
objects/commands.cfg
objects/windows.cfg
htpasswd.users
monitor
cgi.cfg

Configuration

nano /opt/nagios/etc/nagios.cfg

Make sure that check_external_commands is set to 1:

# EXTERNAL COMMAND OPTION
# This option allows you to specify whether or not Nagios should check
# for external commands (in the command file defined below). By default
# Nagios will *not* check for external commands, just to be on the
# cautious side. If you want to be able to use the CGI command interface
# you will have to enable this.
# Values: 0 = disable commands, 1 = enable commands

check_external_commands=1

Extra Plugins

We can also add custom plugins to our installation:

docker run --name nagios4  \
-v /opt/nagios/etc/:/opt/nagios/etc/ \
-v /opt/Custom-Nagios-Plugins:/opt/Custom-Nagios-Plugins \
-p 0.0.0.0:8888:80 jasonrivers/nagios:latest