Category Archives: Tech

About technology.

The importance of PID 1 in containers

The Docker platform leverages Docker containers to enable IT operations teams and Developer teams to build, ship and run any application, anywhere. (from

I’ve been working with Docker for 3 years now and seen some cases where an image has to perform some steps before booting the application(s). It’s usual to see that done with a bash script that doesn’t launch the application preceded by an exec command. Let me explain:

Continue reading

Leave a comment

Filed under docker, Tech

[Docker] How to monitor your server(s) with Nagios


Lately I’ve been working with Docker experimenting development setups with JBoss Wildfly, ActiveMQ, Jenkins, Postfix, Nagios, etc. For those who are not familiar with:

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.

You can easily create a container with your ideal setup and deploy your app, in a matter of minutes! You can have fun with Docker, here.

Nagios is a very powerful monitoring tool that can help you to monitor your infrastructure, detect security breaches, spot problems before they occur, etc.
I’ve forked Brian Goff Nagios image and added the possibility to monitor HTTPS by enabling SSL (here). But then, how do I create my configuration files and add them to Nagios?


Based on cpuguy83 Nagios or my image, I’ve created the following Dockerfile:

# Nagios docker modified image

# use tpires/nagios base image (SSL ON)
FROM tpires/nagios

# Install/remove dependencies
ENV DEBIAN_FRONTEND noninteractive

# I've had some troubles trying to configure postfix inside nagios, so let's remove it and later create a postfix image to also be used by other containers.
RUN apt-get remove -y --purge postfix
RUN apt-get install -y msmtp heirloom-mailx
RUN apt-get autoremove -y
RUN apt-get autoclean

RUN chmod +x /

CMD ["/bin/bash", "-c", "/"]

(I’m going to use an external postfix image to send emails. You can, of course, keep and configure postfix inside this image.)
We’re adding an init script, to let us copy configuration file(s) to our Nagios image and edit some of the existing ones. But where will those configuration file(s) come from? Later, we’ll create a nagios configuration image containing them. Let’s have a look at first.


# If $NAGIOS HOME isn't set, set it!
if [ -z $NAGIOS_HOME ];

# Create, if not already, servers configuration directory
if [ ! -d "$NAGIOS_HOME/etc/servers" ];
 mkdir -p $NAGIOS_HOME/etc/servers

# Copy all existing configuration file(s) to Nagios servers directory and uncomment that line in nagios.cfg.
if [ ! -z $CONF_PATH ]; then
 cp -f $CONF_PATH/*.cfg $NAGIOS_HOME/etc/servers/
 sed -i "s|#cfg_dir=$NAGIOS_HOME/etc/servers|cfg_dir=$NAGIOS_HOME/etc/servers|g" $NAGIOS_HOME/etc/nagios.cfg

# mail configuration
# We're setting MSMTP client to connect to our postfix and send emails.
# If you're using an external postfix image don't forget to set an environment variable MAIL.
if [ ! -z /etc/msmtprc ];
 echo 'account postfix' > /etc/msmtprc
 echo 'host postfix' >> /etc/msmtprc
 echo 'port 25' >> /etc/msmtprc
 echo 'from '$POSTFIX_ENV_MAIL >> /etc/msmtprc
 echo 'protocol smtp' >> /etc/msmtprc
 echo 'account default : postfix' >> /etc/msmtprc

 chmod 600 /etc/msmtprc

 cp /etc/msmtprc $NAGIOS_HOME/.msmtprc
 chown nagios:nagios $NAGIOS_HOME/.msmtprc

 # remove postfix from the startup script
 rm -rf /etc/sv/postfix

# Modify system default client to msmtp.
if [ ! -z /etc/mailrc ];
 echo 'set sendmail=/usr/bin/msmtp' > /etc/mailrc
 echo 'set sendmail=/usr/bin/msmtp' >> /etc/nail.rc
 echo 'set smtp=postfix:25' >> /etc/nail.rc  ## i'm using postfix as host due to --link name when starting nagios.
 echo 'set from='$POSTFIX_ENV_MAIL >> /etc/nail.rc

 cp /etc/mailrc $NAGIOS_HOME/.mailrc
 chown nagios:nagios $NAGIOS_HOME/.mailrc
 chown nagios:nagios /etc/nail.rc

# remove localhost configuration (by default is enabled)
rm -f $NAGIOS_HOME/etc/objects/localhost.cfg
sed -i "s|cfg_file=/opt/nagios/etc/objects/localhost.cfg|#cfg_file=/opt/nagios/etc/objects/localhost.cfg|g" $NAGIOS_HOME/etc/nagios.cfg

# add timezone check
sed -i 's|use_timezone=|#use_timezone=|g' $NAGIOS_HOME/etc/nagios.cfg

# start nagios

Our Nagios image is ready! Now let’s create our configuration image with this Dockerfile:

# Docker Nagios Conf


# scratch is a minimal docker image, ideal to hold configuration files.
FROM scratch

ADD configuration-file.cfg /conf/

VOLUME [ "/conf" ]

This image holds our configuration file(s) and now we can start it and import its volume!

Let’s first create our images.

$ cd nagios
$ docker build -t myrepo/nagios .
$ cd conf
$ docker build -t myrepo/nagios-conf .

Now let’s put it to work, by first running our configuration image and then import its volume:

$ docker run -d --name nagios-conf myrepo/nagios-conf /dev
$ docker run -d --name nagios -e CONF_PATH=/conf -e NAGIOSADMIN_PASS=myownpassword -e HOME=/root --volumes-from nagios-conf -v /etc/localtime:/etc/localtime -p 8080:80 myrepo/nagios

# if you've an external postfix image add: --link postfix:postfix

We’re starting our Nagios container setting its configuration path (CONF_PATH), modifying the default password (NAGIOSADMIN_PASS), setting HOME directory, importing configuration files, synchronizing with system localtime and setting 8080 as our external port.

Let’s browse to http://localhost:8080 and Nagios should be up and running!


Filed under Tech

OpenELEC XBMC 12.0 “Frodo” with Raspberry Pi Support


XBMC has released today the long waited XBMC 12 “Frodo”. It has support for Linux, Windows, Mac OS X, Android, Raspberry Pi, Apple TV and Apple iOS.I’ve already compiled it from Raspberry Pi (NOT OFFICIAL links below).

Continue reading


Filed under Tech

SAPO Codebits 2012


I’m proud to say that i’ve been selected to another awesome edition of SAPO Codebits! I’ve participated on Codebits before and let me tell you it’s awesome! Three days that look like one. Forget sleeping, just enjoy! I’m also excited for the fact that Raspberry Pi guys will be there and i’ll have a great opportunity to “feel” the project even closer 😉

Let the *fun* begin! 😀


Leave a comment

Filed under Fun, Tech

Raspberry Pi OpenELEC latest PVR support (DVB-T)

Raspberry Pi Logo

OpenELEC build r12431 has already a nice media_build support, so you don’t need to add media_build support anymore. I’ve already updated my guide, so you won’t get all confused.

Download here the latest OpenELEC build to the moment (r13118).

Leave a comment

Filed under Tech