Running Nagios using virtualizations

Apart from running Nagios on a physical machine, it can also be run inside virtualizations, like almost all other applications. This section is mainly intended for users already familiar with different types of virtualization and willing to run Nagios in such an environment.

Nagios works well both using hardware virtualization such as provided by VMware, Virtual Box, or Hyper-V applications as well as in Linux containers such as Docker.

Containers allow Nagios to run in a shared, single instance of the Linux kernel, which allows better sharing of memory and other resources and is much easier to set up in general—all that is needed is installing Docker, which will take care of provisioning everything else.

Hardware virtualization has the benefit of not sharing the Linux kernel and having dedicated resources such as configuring the amount of available RAM memory—so it is possible to limit the resources that Nagios can use.

Running Nagios inside containers

Containers are an operating system-level virtualization technology. It can be used to run multiple isolated Linux systems on a single Linux machine.


Introduction to containers and Docker as the technology in particular can be found at

The best way to work with Nagios inside Docker is to first create a Docker image using a Dockerfile and then simply run one or more containers using the newly created image.


The Dockerfile’s syntax is described in more details at

The basic Dockerfile to create a Nagios image is very trivial:

FROM ubuntu:14.04 
RUN apt-get update && \ 
  apt-get -y install curl && \ 
  curl | sh 

This will create an image based on Ubuntu version 14.04; install the curl package, then download and run the install script.

To test it, create an empty directory, write the preceding text as a new file called Dockerfile, and then run the following command inside that directory:

docker build --tag automated_nagios_image .

This will create an image using the preceding command.

The next step is to create a script to start both Apache and Nagios. Create a file called in the same directory as Dockerfile with the following contents:

# capture stop signals from Docker
trap stop_all 1 2 3 4 5 6 15
stop_all() {
    echo "Stopping services..."
    /etc/init.d/nagios stop
    apachectl stop
start_all() {
    echo "Starting services..."
    apachectl start
    /etc/init.d/nagios start
# start services and wait indefinitely
sleep 10000d

This script will start Apache and Nagios and then terminate them once a terminate signal (such as CtrlC) is received.

Then add the following lines to Dockerfile:

CMD ["sh", ""]

The first line specifies that TCP port 80 (the port that is used by the http protocol) should be exposed. The next line adds the newly created file to the image. Finally, the last line specifies when the image is started; it should run the script.

Now let’s rebuild the image:

docker build --tag automated_nagios_image .

As the next step, we can simply start it:

docker run -P automated_nagios_image

This will start a new container using the newly created image. The -P flag specifies that the exposed ports should be redirected. This will basically make the Apache available at a random port on all IP addresses of the Docker host machine.


Port redirection in Docker is described in more details at

We can also force providing port 80 as any port on the docker host machine with the following command:

docker run -p 8080:80 automated_nagios_image

This will export the Nagios web server as port 8080 on the local machine. This way it can be accessed with: http://(ip-address):8080/nagios.

At this point, we can run one or multiple Docker containers based on the image that already includes a precompiled version of Nagios and a web server, with a predefined password.

Installing Nagios inside virtual machines

Nagios can also be easily run as a separate virtual machine using hardware virtualizations such as those provided by VMware, Virtual Box, or Hyper-V solutions.


Virtualization and its types are described in more details at

The process of setting up Nagios inside a virtual machine is very similar to setting it up natively or inside a container. All that is needed is to run a Linux virtual machine. Using the latest Ubuntu LTS, such as 16.04, is a safe choice for a distribution.

All that is needed is to set it up or download a ready to use image, such as from

The next step is to ensure that the curl command is available:

apt-get update ; apt-get -y install curl

Next, simply run the same script to download and run the automated setup script:

curl -sSL
install/master/ | sh

Please note that setting up Nagios requires the machine to be able to access the Internet for downloading the required packages as well as the Nagios sources.

At this point, the compilation should succeed and the machine will have Apache and Nagios already set up.

After this step, it is possible to clone or create a template of the machine to be able to start new instances with Nagios already installed. The procedure for creating a clone or template may vary depending on the virtualization technology that you are using.

Another option is to use the official Nagios virtual machines. They are available as a commercial offering and can be purchased from the following link:

It is also possible to use the Nagios XI virtual machine image, which can be downloaded from the following link:

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur


Submit a Comment

Your email address will not be published. Required fields are marked *

1 × four =