I have been writing a lot about Docker 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 June there have been two further releases. 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 …..
Fig is a great tool which allows you orchestrate your containers using a single configuration file which looks something like;
webserver: image: russmckendrick/nginx-php volumes: — /home/containers/web:/var/www/html/ ports: — 80 environment: PHP_POOL: testapp VIRTUAL_HOST: myawesometest.app.mckendrick.eu links: — databaseserver:db databaseserver: image: russmckendrick/mariadb volumes: — /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 session 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 container and database container, 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;
[[email protected] ~]# curl -L https://github.com/docker/fig/releases/download/0.5.2/linux > /usr/local/bin/fig [[email protected] ~]# chmod +x /usr/local/bin/fig [[email protected] ~]# fig Punctual, lightweight development environments using Docker.
Usage: fig [options] [COMMAND] [ARGS…] fig -h| — help
Options: — 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)
Commands: 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 session 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 Module 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 post 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 Dockerfile to run using my own base build and then pushed it as a trusted build.
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-gen to serve the new domain.
Docker on CentOS 7
All of this is great, however the repo version of Docker in CentOS 7 is old, its 0.11 which for a piece of software as fast moving as Docker is ancient. Luckily there is a repo on copr which is hosting EL7 compatible RPMs of the latest builds. As I rebuild my servers all the time I knocked out a small one liner which installs the later version of Docker on a CentOS 7 server;
curl -fsS https://raw2.github.com/russmckendrick/docker-install/master/install | bash