System administration, tricks and tips from an old school web-hacker. All words and opinions are my own.

Efficient Docker containers using Nginx and Harp.JS

· Read in about 2 min · (261 Words)

We’ve been working on speeding up our Docker deploys over the last little while. We took deploys of a simple Harp site from 40 seconds to approximately 3 using this method - but we were still running the Harp server.

The Harp server took approximately 20-30MB of RAM at version 0.8 - but had balooned to approximately 60-80MB at version 0.11. We wanted to use the newer Harp, but tripling the memory usage was a bit of a problem.

While chatting yesterday, Jody recommended we look at harp compile which had totally skipped my mind - in about an hour of testing and tweaking, we created a new Dockerfile for our Harp base container:

FROM octohost/nodejs

RUN npm install harp -g
RUN add-apt-repository -y ppa:nginx/stable
RUN apt-get update
RUN apt-get -y install nginx
RUN mkdir /srv/www
ADD default /etc/nginx/sites-available/default
ADD nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD nginx

This installs Harp and Nginx and as a last step ADDs the proper config files for nginx.

Then, in the Harp repository, we add this simple Dockerfile:

FROM octohost/harp-nginx

WORKDIR /srv/www

ADD . /srv/www/
RUN harp compile

EXPOSE 80

CMD nginx

Deploys now:

  1. Use nginx as the web server.
  2. Use only 6MB of memory - down from 60MB.
  3. Take approximately 10 seconds. (Up from 3-6 - will try and find speedups here as well.)

That’s a win in my books.

You can grab the source to our base container here or just docker pull octohost/harp-nginx.

To see a working Harp site - take a look here for the source and here for the running site.