In past systems administration roles I used Nagios for systems and applications monitoring. I always found it flexible for my needs allowing me to write health checks for anything that the open source community had not already provided. As I am trying to pickup new DevOps skills, I completed a get started with Docker tutorial and thought, deploying Nagios at home via Docker would be an interesting project. However, it was a bit tricky and I have only created an image that monitors itself, so far.
To test things out, I ran the latest official CentOS image and installed Nagios and its dependencies. I chose CentOS because I have a background in Red Hat. Installing Nagios was easy enough. I was able to walk through the CentOS install as documented. The tricky part was Docker prevents use of systemd because Docker was designed for securely running a single service per container. Running the Nagios service and a dependency like Apache web server is not considered best practice. For experimentation at home, I looked for a solution.
I decided to create a simple shell script to start the Nagios and Apache services. The shell script is then called via the CMD instruction in my nagios Dockerfile. The Dockerfile and shell script can be found below or on GitHub. For good measure I also pushed my Nagios image up to Docker Hub.
# Install prerequisites RUN yum install -y epel-release gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix make
# Set the working directory WORKDIR /nagios/
# Copy into /nagios COPY . /nagios/
# Download source RUN wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz RUN tar xzf nagioscore.tar.gz
# Set the working directory WORKDIR /nagios/nagioscore-nagios-4.4.3/
# Compile RUN ./configure RUN make all
# Create User and Group RUN make install-groups-users RUN usermod -a -G nagios apache
# Install Binaries RUN make install
# Install Service-Daemon RUN make install-daemoninit RUN systemctl enable httpd.service
# Install Command Mode RUN make install-commandmode
# Install Configuration Files RUN make install-config
# Install Apache Config Files RUN make install-webconf
# Create nagiosadmin User Account RUN htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Install Nagios plugins dependencies RUN yum install -y which gettext automake autoconf openssl-devel net-snmp net-snmp-utils RUN yum install -y perl-Net-SNMP
# Set working directory WORKDIR /nagios/
# Downlaod Nagios Plugins RUN wget --no-check-certificate -O /nagios/nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz RUN tar zxf nagios-plugins.tar.gz
# Set working directory WORKDIR /nagios/nagios-plugins-release-2.2.1/
# Install Nagios plugins RUN ./tools/setup RUN ./configure RUN make RUN make install
# Start Apache and Nagios CMD ["/bin/bash", "/nagios/start.sh"]