Skip to main content

Posts

Showing posts from October, 2014

Docker: using Monit to manage processes

I know that Docker has been built to run only one process per container (in fact it has no init process like a "normal" operating system), but I like to have an open port to connect to a container to inspect what's going on there. There's another case for which I need more than one process: one of the web sites I manage is served by a node.js http server proxyed by Apache. To allow for more high availability I start two node processes serving the same site, so that my container needs to have at least two node.js processes running at the same time and listening to two different ports. I found Monit handy to accomplish this task. The following example shows how to build an image that starts Monit which starts and monitors only the SSH daemon. As I described in a previous article , I use a setup script to build a new image, so that the Dockerfile is as small as possible. I'm not showing here the whole Dockerfile , but only the components needed to set up Monit

Docker: setting up a reusable build environment

Working with Docker I found a Dockerfile structure that can be reused for different images so that I can have a uniform building enviroment. Beside this, I chose to do most of the work in a shell script running in the container; this has some advantages: you can leverage the full power of the shell and it keeps the total number of levels low. Remember that Docker can handle at most 127 layers while using the devicemapper, while AUFS can handle something near 42 layers. Dockerfile structure My Dockerfiles are divided into four main sections: 1) copy files; 2) run setup; 3) expose ports; 4) set the starting command. Copy files First copy all the necessary files into the container. If there are lots of files it's better to enclose them in a tgz archive to have only a few "COPY" commands. Remember that each command in a Dockerfile creates a new layer, so it's better to have as few as possible. COPY ./website.tgz /home/ ADD ./start.sh /start.sh I use /h