I have been writing a lot about Dockerexternal link and how I have used it over the last several months so why another another post?

Well, for a start it has a lot of momentum. Since Docker went 1.0 in Juneexternal link there have been two furtherexternal link releasesexternal link . Also, the ecosystem which has sprung up around Docker is keeping up the same pace as well.

This means that there is always a lot of new shinny things to play with such as …..


Since Docker released 1.0 they have purchasedexternal link Orchard Laboratoriesexternal link who wrote the excellent Figexternal link .


Fig is a great tool which allows you orchestrate your containers using a single configuration file which looks something like;

    image: russmckendrick/nginx-php
   — /home/containers/web:/var/www/html/
   — 80
 PHP_POOL: testapp
 VIRTUAL_HOST: myawesometest.app.mckendrick.eu
   — databaseserver:db
    image: russmckendrick/mariadb
   — /home/containers/database:/var/lib/mysql/

In the example above when fig up is run in the same directory as the fig.yml it will launch two containers and link them together.

In the terminal sessionexternal link below you can see that I launch an NGINX Proxy (more on that later in this post), and then used fig to launch a web containerexternal link and database containerexternal link , the web container runs a simple PHP script which prints the containers IP address to the screen. Once the containers are up and running I then scale the web containers up to 5 containers and then back down to a single container.


Fig can be installed using the following commands;

[root@docker ~]# curl -L https://github.com/docker/fig/releases/download/0.5.2/linux > /usr/local/bin/fig
[root@docker ~]# chmod +x /usr/local/bin/fig
[root@docker ~]# fig
Punctual, lightweight development environments using Docker.

 fig [options] [COMMAND] [ARGS…]
 fig -h| — help

 — verbose Show more output
 — version Print version and exit
 -f, — file FILE Specify an alternate fig file (default: fig.yml)
 -p, — project-name NAME Specify an alternate project name (default: directory name)

 build Build or rebuild services
 help Get help on a command
 kill Kill containers
 logs View output from containers
 ps List containers
 rm Remove stopped containers
 run Run a one-off command
 scale Set number of containers for a service
 start Start services
 stop Stop services
 up Create and start containers

You need to be sure you are running the latest version of Docker, see the last section of this post for details on how to install Docker 1.2 on CentOS 7.

Further reading …..

NGINX Reverse Proxy

The terminal sessionexternal link in the previous section of this post shows that I was able to launch my containers using Fig & connect to the URL myawesometest.app.mckendrick.eu which then went on to be load balanced as I scaled the web server containers, so how does that work?

Previously I had been using @garethr’s Puppet Moduleexternal link to manage and deploy my containers alongside a NGINX reverse proxy on the host machine. While this worked fine, it did seem a little overkill cerry on using Puppet to manage my containers if I was going to be using Fig.

After consulting the all knowing Google I stumbled across Jason Wilder’s blog postexternal link about how to configure an Automated Nginx Reverse Proxy for Docker. It seemed like the perfect solution to the problem I was having so I ported his Dockerfileexternal link to run using my own base buildexternal link and then pushed it as a trusted buildexternal link .

This means that with a single command …..

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock -t russmckendrick/nginx-proxy

….. I can launch a container which runs on port 80 and then listens for containers being launched, if they have the VIRTUAL_HOST environment variable set NGINX will be reconfigured automatically using docker-genexternal link to serve the new domain.

Couple this with a wildcard DNS recordexternal link & you have a basic self-service PaaSexternal link .

Docker on CentOS 7

All of this is great, however the repo version of Docker in CentOS 7external link is old, its 0.11external link which for a piece of software as fast moving as Docker is ancient. Luckily there is a repo on coprexternal link which is hosting EL7 compatible RPMs of the latest buildsexternal link . As I rebuild my servers all the time I knocked out a small one linerexternal link which installs the later version of Docker on a CentOS 7 server;

curl -fsS https://raw2.github.com/russmckendrick/docker-install/master/install | bash