<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yoanis Gil Delgado on Medium]]></title>
        <description><![CDATA[Stories by Yoanis Gil Delgado on Medium]]></description>
        <link>https://medium.com/@yoanis_gil?source=rss-690c49c01fa2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fXuV6LaiPI0aOPNC.jpg</url>
            <title>Stories by Yoanis Gil Delgado on Medium</title>
            <link>https://medium.com/@yoanis_gil?source=rss-690c49c01fa2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 02:50:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yoanis_gil/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python + Docker: From development to production: Episode I]]></title>
            <link>https://medium.com/@yoanis_gil/python-docker-from-development-to-production-episode-i-427674710f3e?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/427674710f3e</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Tue, 16 May 2017 02:55:22 GMT</pubDate>
            <atom:updated>2017-05-16T02:55:22.096Z</atom:updated>
            <content:encoded><![CDATA[<p>For the last two years or so I’ve been using Docker to deliver almost every single project I’ve been involved with. It’s been a long journey where I’ve had the opportunity to learn an interesting set of new technologies and most importantly how to get code shipped to production in a reliable, predictable and trustable way.</p><p><a href="https://www.python.org/">Python</a> is the language I feel most comfortable with, which means that those projects (mostly web applications or web APIs) have been developed with heavy usage of frameworks and libraries available under the language’s ecosystem.</p><p>I’ll be sharing my journey this far in a series of blog posts (hopefully only two). The first one, which I named Episode I focuses on the development experience. Episode II is an overview of the different Cloud solutions I’ve worked with for deploying Docker applications and how to run the demo application on container friendly environment.</p><h3>The Application</h3><p>For the purpose of this demo we’re going to use a very simple <a href="http://flask.pocoo.org/">Flask</a> application named <a href="https://github.com/yoanisgil/easygeoip">Easy GeoIP</a>. The application comprises three main components:</p><ul><li>An endpoint which takes-in a Domain Name or IP Address and uses the MaxMind City database to return all of the information associated to the given Domain Name/IP Address.</li><li>A web page, which will present the information returned by the endpoint mentioned above, in a user-friendly way (see screenshot below).</li><li>A PostgresSQL database which is used to fill-in the timezone for the provided Domain Name or IP Address, when not available in the MaxMind City Database.</li></ul><p>Below a high-level view of the application architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*hqxfhPn2ojnMgZUi.png" /></figure><p>and then you can enter any IP Address/Domain Name of your choice and you should something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uq18VV4tQTcsqa1K.png" /></figure><p>NOTE: The PostgresSQL database was generated from the Shapefiles available <a href="http://efele.net/maps/tz/world/">here</a>. For more details on how this database was created take a look at this <a href="https://github.com/yoanisgil/tz_world">link</a></p><h3>Running the Python App for the first time</h3><p>Let’s start with the basics and get the application running. First we need to clone the application repository and checkout the Git tag we will be using through this article:</p><pre>- git clone https://github.com/yoanisgil/easygeoip.git<br>- git checkout blog-episode-i</pre><p>We can now build the Docker which we will later use to create the container running the application:</p><pre>- docker-compose build app</pre><p>this might take a few mintues, but once the build is finished you should see something like this:</p><pre>Removing intermediate container 4e33a37b9b69<br>Step 16/16 : CMD supervisord -u www-data -n -c /etc/supervisor/supervisord.conf<br> ---&gt; Running in 2f8f80a4405d<br> ---&gt; 368383a4d379<br>Removing intermediate container 2f8f80a4405d<br>Successfully built 368383a4d379</pre><p>with the image built, we can now launch the application:</p><pre>- docker-compose up<br>    app_1          |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)<br>    app_1          |  * Restarting with stat<br>    tz_world_db_1  | LOG:  database system was shut down at 2017-04-20 10:53:35 UTC<br>    tz_world_db_1  | LOG:  MultiXact member wraparound protections are now enabled<br>    tz_world_db_1  | LOG:  autovacuum launcher started<br>    tz_world_db_1  | LOG:  database system is ready to accept connections</pre><p>after which you can now go visit <a href="http://localhost:5000/">http://localhost:5000</a>, and you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-uSfGnvQIYzlV2fP.png" /></figure><h3>First Dive into The Application</h3><p>Ok, that was quick. In just a matter of minutes we were able to have a fully working application and with very little effort. Let’s see how was this possible. The very first thing that we did was to run:</p><pre>- docker-compose build app</pre><p>This command is telling Docker Compose to build the service app, which is defined as follows in the <a href="https://github.com/yoanisgil/easygeoip/blob/blog-episode-i/docker-compose.yml">docker-compose.yml file</a>:</p><p>Before we take an in-depth look to the Docker Compose file let’s go through the Dockerfile we’re using to build the application’s image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21df786ebd16b89a69a8dbea99fba91c/href">https://medium.com/media/21df786ebd16b89a69a8dbea99fba91c/href</a></iframe><p>The Dockerfile it’s pretty explanatory by itself, however let me highlight some of the most important elements present in it:</p><ul><li>We’re using python:2.7-slim as our base image since we want to keep our Docker image as light as possible. This is very handy specially when it comes to deployment since the image needs to be pulled before been deployed.</li><li>Those instructions which are not supposed to change very often (apt-get install, apt-get update, etc) are added very early in the file so that we can benefit from the caching mechanisms provided by Docker.</li><li>The requirements.txt file is added independently from the application code. This is again, to speed-up the build process since app&#39;s dependencies should not change that often.</li><li>The container entrypoint is <a href="http://supervisord.org/">supervisord</a>. The reason we need supervisord is because our container needs to run both NGINX and uWSGI. Also because other many goodies that come with supervisord, like that it can act as a process reaper, make sure processes are always running, etc.</li><li>Neither NGINX, nor uWSGI are running as root (not even supervisord). They all run as the user www-data.</li></ul><p>With the Dockerfile now explained, let’s now break down the Docker Compose file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9d696543c96a2e7b6da83c24905c61c/href">https://medium.com/media/d9d696543c96a2e7b6da83c24905c61c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d712d05e58a016c84cdcfe69be8d9bd0/href">https://medium.com/media/d712d05e58a016c84cdcfe69be8d9bd0/href</a></iframe><p>Go ahead, play and test the application, modify it and play with it. You will see the development experience it’s quite the same as if it was running outside Docker :).</p><h3>What’s Next??</h3><p>With the development environment setup and fully working it’s now time to deploy to production. But how do we do that? For sure we want the process to be trustworthy and as predictable as possible. Also, what solutions, cloud-based or not, are available out there that help the most with our application deployment?</p><p>This and more will be the subject of Episode II, so stay tuned :).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=427674710f3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Jenkins on top of a Flocker Cluster using Docker and Ansible]]></title>
            <link>https://medium.com/@yoanis_gil/running-jenkins-on-top-of-a-flocker-cluster-using-docker-and-ansible-ccad738e2888?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccad738e2888</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Tue, 05 Apr 2016 20:26:04 GMT</pubDate>
            <atom:updated>2016-04-05T20:26:04.816Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://www.valtech.com/">Valtech Canada</a> we’re always looking for new challenges and ways to improve our technology stack which is why I set my self onto the task of building a <a href="https://jenkins.io/index.html">Jenkins</a> cluster using Docker’s <a href="https://docs.docker.com/engine/userguide/networking/get-started-overlay/">Multi-Host Networking</a> , <a href="https://docs.docker.com/swarm/overview/">Swarm</a> and <a href="https://docs.docker.com/compose/overview/">Compose</a>.</p><p>Before I begin I’d like to clarify that this article was written using:</p><pre>- Docker 1.10.0<br>- Docker Compose 1.6.2<br>- Docker Machine 0.6.0</pre><p>It also makes use of Amazon Web Services (AWS for short) EC2 instances for which you need to create an account <a href="https://aws.amazon.com/">here</a> if you don’t already have one.</p><h3>Intro</h3><p>The goal is to be able to run everything inside containers, which of course demands the ability to run a Jenkins Master and as many slaves as possible inside containers. So let me state my goals in a concise way:</p><pre>1 - The Jenkins Master can run in any node of the Swarm cluster and the deployment must be durable.<br>2 - Jenkins slaves can run in any node of the Swarm Cluster and they must provide out of the box support for building Docker images as well as for running containers.</pre><p>Goal #1 is very important and it’s what this article is mainly about and there will be a follow up article on #2 since that goal by itself it’s quite lengthy and non-trivial.</p><p>Let’s break goal #1 into pieces:</p><pre>1.a - The Jenkins Master can run in any node of the Swarm Cluster.<br>1.b - The deployment of the Jenkins Master must be durable.</pre><p>The first item does not take much thinking, nor much time to implement, since all we need is a properly configured Swarm Cluster and that’s about it. But having a durable deployment of the Jenkins master, well that’s where the fun begins :).</p><p>But first, what does <em>durable deployment</em> means in this specific context? What I’d like to achieve is:</p><pre>- In the case of failure, like when a Swarm Node crashes, we should not incur in any data loss (and possible no data corruption). <br> - It should be as easy as possible to relocate the Jenkins Master to a different node on the Swarm Cluster while keeping all existing build configurations, jobs definitions, etc.</pre><p>If you’ve been into Docker long enough you will know that those two statements above are not easy to deal with, specially in the context of a Swarm Cluster. Why?</p><p>To start with we need to make sure that the Jenkins installation folder it’s externalized, i.e it uses a data volume so that changes made to the Jenkins configuration can survive across containers. But this is not good enough in the case of Swarm Cluster since the container might be scheduled for execution in any node of the Swarm Cluster.</p><p>Luckily for us support for volume plugins was added as an <a href="https://github.com/docker/docker/blob/master/CHANGELOG.md#170-2015-06-16">experimental feature in Docker 1.7.0</a> and made it to production grade <a href="https://github.com/docker/docker/blob/master/CHANGELOG.md#180-2015-08-11">at version 1.8.0</a> . So, how exactly does volume plugins comes into rescue? Let’s take a look at the<a href="https://docs.docker.com/engine/extend/plugins_volume/">Volume Plugin documentation</a>:</p><pre>Docker Engine volume plugins enable Engine deployments to be integrated with external storage systems, such as Amazon EBS, and enable data volumes to persist beyond the lifetime of a single Engine host.</pre><p>which is a way of saying that data volumes are no longer bounded to a single host and could actually be reused across different hosts. Then all we need is a volume plugin that can follow the Jenkins Master container wherever the later gets deployed. Right? You can find a list of existing volume plugins <a href="https://docs.docker.com/engine/extend/plugins_volume/">here</a> which I went through more than once and after weighting several factors, such as pricing, performance and project activity, I narrowed it down to two elements:</p><ul><li><a href="https://clusterhq.com/flocker/introduction/">Flocker by ClusterHQ</a></li><li><a href="https://github.com/libopenstorage/openstorage">OpenStorage</a></li></ul><p>Unfortunately I’ve not being able to use OpenStorage as much I’d love to, mainly because of <a href="https://github.com/libopenstorage/openstorage/issues/119">this issue</a> and also because I really wanted to give it a try running a Swarm Cluster on AWS (even after some assh* stole my AWS credentials I accidentally committed to GitHub and I ended up with a $2400 bill on my AWS account. But that’s another story for different post). This leaves us with FlockerHQ.</p><h3>Enter Flocker</h3><p>Somewhere alone this tool <a href="https://clusterhq.com/flocker/introduction/">introductory page</a> you can read:</p><pre>Flocker manages Docker containers and data volumes together. When you use Flocker to manage your stateful microservice, your volumes will follow your containers when they move between different hosts in your cluster.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*w0SPESgzX8ROQQfh.png" /></figure><p>Et voilà! That’s precisely what we need!! Now, when it comes to installing Flocker there are two installation options:</p><ul><li>Using a <a href="https://aws.amazon.com/cloudformation/">CLoud Formation</a> template</li><li>Manual installation</li></ul><p>I must confess that I’ve zero knowledge on Cloud Formation which is why I went for the manual installation option. I did give a try to using the Cloud Formation template but it creates by default M3 instances which are too expensive for me, so I was left with no choice but manual installation. I admit I could have tried editing the Cloud Formation template but where is the fun in that :D? Anyhow Manual installation it was and this is where things gets even more interesting.</p><h3>Installing Flocker manually</h3><p>Installing Flocker manually it’s not an easy task and you can see by your self if you follow <a href="https://docs.clusterhq.com/en/latest/docker-integration/manual-install.html">the manual</a>. I believe I did about 2 manual installs before realizing that I needed a way of automating all of the work of installing software dependencies, generating certificates/private keys, etc. Luckily for me I remembered <a href="http://nathanleclaire.com/blog/2015/11/10/using-ansible-with-docker-machine-to-bootstrap-host-nodes/">this post</a> by the great Nathan LeClaire which explains how use Docker/Compose and <a href="https://www.ansible.com/">Ansible</a> to provision Docker Machine nodes.</p><p>As a result I’ve created <a href="https://github.com/yoanisgil/flokenstein">flokenstein</a> which eases the creation of Flocker cluster. Please be aware that as the moment of writing this script only supports AWS. Go ahead and <a href="https://github.com/yoanisgil/flokenstein/blob/master/README.md">follow the instructions</a> and get back once you’re done ;)</p><h3>Running Jenkins with Flocker</h3><p>By now you should have a working Swarm/Flocker cluster and you shoul be in the position of running a Jenkins container which takes advantage of Flocker. First:</p><pre>git clone <a href="https://github.com/yoanisgil/flocker-cluster.git">https://github.com/yoanisgil/flocker-cluster.git</a><br>cd flocker-cluster</pre><p>Since we want to keep the entire Jenkins folder inside a Flocker volume we need to make sure it’s indeed copied over to the target volume. First lets launch our Jenkins container:</p><pre>$ JENKINS_HOME=/tmp/jenkins_home docker-compose up -d jenkins</pre><p>which should produce something like this:</p><pre>Creating network &quot;flockercluster_jenkins&quot; with driver &quot;overlay&quot;<br>Creating volume &quot;flockercluster_jenkins&quot; with flocker driver<br>Pulling jenkins (jenkins:2.0-beta-1)...<br>swarm-node-01: Pulling jenkins:2.0-beta-1... : downloaded<br>swarm-master: Pulling jenkins:2.0-beta-1... : downloaded</pre><p>and if everything went all right, then running docker-compose logs should report back lines like the ones below:</p><pre>jenkins_1 | INFO: Loaded all jobs<br>    jenkins_1 | Apr 05, 2016 3:15:47 AM jenkins.InitReactorRunner$1 onAttained<br>    jenkins_1 | INFO: Completed initialization<br>    jenkins_1 | Apr 05, 2016 3:15:47 AM hudson.WebAppMain$3 run<br>    jenkins_1 | INFO: Jenkins is fully up and running<br>    jenkins_1 | --&gt; setting agent port for jnlp<br>    jenkins_1 | --&gt; setting agent port for jnlp... done</pre><p>Let’s grab the IP address where our Jenkins instance is running by using docker ps:</p><pre>$ docker ps --format=&quot;{{.Ports}} {{.Names}}&quot;<br>52.90.38.105:8080-&gt;8080/tcp, 50000/tcp swarm-node-01/flockercluster_jenkins_1</pre><p>This clearly states than Jenkins is available at <a href="http://52.90.38.105:8080/">http://52.90.38.105:8080</a> (<em>NOTE</em>: You will most certainly get a different IP address when running docker ps — format=”{{.Ports}} {{.Names}}”) so make sure you grab the right one. Also, make sure that port 8080 is open and available to the world, in which case the Inbound Ports configuration for the docker-machine security group should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mnmpMrcO4_TNxGdP.png" /></figure><p>If you go visit the IP address/Port where Jenkins is running, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hNioE7EgVRWO61A3.png" /></figure><p>Now let’s copy Jenkins existing installation folder to our Flocker volume. First grab the container ID of the container:</p><pre>$ docker ps --format=&quot;{{.ID}} {{.Image}}&quot;</pre><p>this could return several lines so make sure you grab the ID of the container where the image name is jenkins:2.0-beta-1. In my case the command above outputs:</p><pre>b94dcc8bad09 jenkins:2.0-beta-1</pre><p>so now I run:</p><pre>$ docker exec -u root -ti  b94dcc8bad09 cp -avr /var/jenkins_home /tmp</pre><p>to copy all files from /var/jenkins_hometo /tmp/jenkins_home</p><p>With the Jenkins home already copied to the Flocker volume we can now recreate our Jenkins container:</p><pre>$ docker-compose stop jenkins<br>$ docker-compose rm jenkins<br>$ JENKINS_HOME=/var/jenkins_home docker-compose up -d jenkins<br>Creating volume &quot;flockercluster_jenkins&quot; with flocker driver<br>Creating flockercluster_jenkins_1</pre><p>The later operation might take some time to complete, specially if the container is scheduled to run on a different machine than the previous run, since the Flocker volume (which is actually an <a href="https://aws.amazon.com/ebs/">EBS volume</a>) needs to be re-attached to the node running the Jenkins container.</p><p>So again, let’s grab the IP address where the Jenkins container is running:</p><pre>$ docker ps --format=&quot;{{.Ports}} {{.Names}}&quot;<br>52.90.38.105:8080-&gt;8080/tcp, 50000/tcp swarm-node-01/flockercluster_jenkins_1</pre><p>and if we go visit the configured IP address on port 8080 we should see the same welcome screen as before. But this time we go through the installation procedure. So let’s grab that default administrator password Jenkins created for us:</p><pre>$ docker ps --format=&quot;{{.ID}} {{.Image}}&quot; <br>a5d22f24c133 jenkins:2.0-beta-1<br>$ docker exec -ti a5d22f24c133 cat /var/jenkins_home/secrets/initialAdminPassword<br>AUTO_GENERATED_JENKINS_ADMIN_PASSWORD</pre><p>Enter the auto generated password in the password field and just go through the installation procedure (installation of default plugins, admin account creation, etc). Eventually you will be presented with a screen like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jc6CAxPdAAJuOGNI.png" /></figure><p>So how do we know this whole Flocker volume thing is working? By doing two things:</p><pre>- Removing the existing container<br>- Rescheduling the container to run on a different host</pre><p>First let’s grab the host where the Jenkins container is running:</p><pre>$ docker ps --format=&quot;{{.ID}} {{.Image}} {{.Names}}&quot;<br>a5d22f24c133 jenkins:2.0-beta-1 swarm-node-01/flockercluster_jenkins_1</pre><p>which indicates that the container is running on the swarm-node-01. Let’s keep that in mind so that the next time we ask Swarm to run a Jenkins container it’s not scheduled to run on that particular node.</p><p>In order to remove the container just do:</p><pre>$ docker-compose stop jenkins<br>WARNING: The JENKINS_HOME variable is not set. Defaulting to a blank string.<br>Stopping flockercluster_jenkins_1 ... done<br>$ docker-compose rm jenkins</pre><p>And now let’s ask Swarm to run the container on a node other than swarm-node-01 (if you’re container was running on the swarm-master node then change -e constraint:node==swarm-master to -e constraint:node==swarm-node-01) :</p><pre>$ COMPOSE_HTTP_TIMEOUT=120 JENKINS_HOME=/var/jenkins_home docker-compose run -d -e constraint:node==swarm-master -p 8080:8080 jenkins<br>Creating volume &quot;flockercluster_jenkins&quot; with flocker driver</pre><p>This operation will take, again, some time to complete because the EBS volume needs to be detached from the instance it was attached to and then re-attached to the node where the container is scheduled to run (which is why I’ve specified a longer timeout for compose … just in case ;)). Again go grab the IP address where Jenkins is running:</p><pre>$ docker ps --format=&quot;{{.Ports}} {{.Names}}&quot;<br>52.91.20.173:8080-&gt;8080/tcp, 50000/tcp swarm-master/flockercluster_jenkins_run_1</pre><p>and you should be exactly at where you left the Jenkins installation, i.e a brand new Jenkins installation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6AVoJo1QhvfKc8uZ.png" /></figure><p>Neat right? You could for instance add a new node using flokenstein and use a constraint to ensure a Jenkins container is scheduled for execution on the new node and you will see how our Flocker volume will just follow up with the container.</p><h3>That’s all folks</h3><p>By now you should have a better idea what Flocker brings into the game and how it can help you handle containers working with persistent data. I also hope that by now you also understand how tools and technologies like Docker/Swarm/Compose and Multi-Host networking opens the door to a whole new world of possibilities and most importantly to a new degree of flexibility and control over your infrastructure. I would say that the approach described throughout this article needs to be battle tested before it can make it to production but I believe it presents a far more flexible/open approach for doing CI/CD on these days.</p><p>On a follow up article we will build upon the work described on this post to create a Jenkins cluster powered by containers ;). Keep in touch!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccad738e2888" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running an Elasticsearch cluster on Docker 1.9 with Swarm and Compose]]></title>
            <link>https://medium.com/@yoanis_gil/running-an-elasticsearch-cluster-on-docker-1-9-with-swarm-and-compose-efabe110c675?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/efabe110c675</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Wed, 20 Jan 2016 13:37:06 GMT</pubDate>
            <atom:updated>2016-05-17T19:46:30.614Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>I recently came across <a href="http://nathanleclaire.com/blog/2015/11/17/seamless-docker-multihost-overlay-networking-on-digitalocean-with-machine-swarm-and-compose-ft.-rethinkdb/">this excellent article</a> by Nathan LeClaire which goes about spinning up a <a href="https://www.rethinkdb.com/">RethinkDB cluster</a> on the cloud, powered by Docker 1.9 and Swarm 1.0. It illustrates how using tools like <a href="https://docs.docker.com/compose/">Docker Compose</a> and <a href="https://www.google.ca/webhp?sourceid=chrome-instant&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=docker%20machine">Docker Machine</a> one can launch a cluster in just a few minutes. This is all possible thanks to one of Docker’s coolest feat ever: Multi-Host Networking.</p><p>Multi-Host networking was labeled production grade on November 2015 and you can read more about it <a href="https://blog.docker.com/2015/11/docker-multi-host-networking-ga/">here</a>. This blog post assumes you’re somewhat familiar with this particular feature, but if you’re not take look at <a href="https://docs.docker.com/engine/userguide/networking/get-started-overlay/">this link</a> and maybe <a href="https://www.youtube.com/watch?time_continue=45&amp;v=B2wd_UigNxU">this video</a> and you should be good to go.</p><p>There are two main parts on this article:</p><ol><li>Launching a Swarm cluster.</li><li>Launching an <a href="https://www.elastic.co/products/elasticsearch">Elasticsearch</a> cluster.</li></ol><p>On the first part we will power up and Swarm cluster comprising one master and three nodes, which we will later use on part two to launch our Elasticsearch cluster. Before we move onto the fun stuff, make sure that:</p><ul><li>You’re running Docker &gt;= 1.9 (verify with <em>docker version</em> )</li><li>Docker Compose = 1.5.0 (verify with <em>docker-compose –version. </em><strong><em>NOTE:</em></strong><em> If you Compose 1.6 or greater you be aware that networking is no longer an experimental feature so the parameters used for defining a software network do no longer apply</em>)</li><li>Docker Machine &gt;= 0.5.0 (verify with <em>docker-machine –version</em>)</li><li>Have a valid/active <a href="https://www.digitalocean.com/">Digital Ocean</a> account. If you don’t you can get one <a href="https://www.digitalocean.com/?refcode=b868d5213417">here</a>.</li></ul><p>The “source code” of this article is available <a href="https://github.com/yoanisgil/docker-elasticsearch-cluster">on GitHub</a>. PRs are welcomed ;)</p><h3>The Swarm Cluster</h3><p>Before we can do anything else we need a few machines for our cluster, which we can be done in no time with Docker Machine. One thing I really love about Machine it’s the number of Cloud providers <a href="https://docs.docker.com/machine/drivers/">it supports</a> and how easy it is to launch a fully working Docker environment from the command line and have it running in a matter of minutes.</p><p>So, go ahead and grab your Digital Ocean access token. If you’re new to Digital Ocean, take a look at the <em>How To Generate a Personal Access Token</em> first section first part <a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2">this tutorial</a> .</p><p>We will need to setup 5 environment variables:</p><pre><strong>export</strong> DIGITALOCEAN_ACCESS_TOKEN=YOUR_DIGITAL_OCEAN_GOES_HERE<br><strong>export</strong> DIGITALOCEAN_IMAGE=debian-8-x64<br><strong>export</strong> DIGITALOCEAN_PRIVATE_NETWORKING=true<br><strong>export</strong> DIGITALOCEAN_REGION=sfo1<br><strong>export</strong> DIGITALOCEAN_SIZE=1gb</pre><p>Each one of these environment variable will be used later by Docker Machine when creating the servers for running Docker on the cloud. Let’s take a look at the meaning of each of these variables:</p><ul><li>DIGITALOCEAN_ACCESS_TOKEN: This is the token which identifies your account so Digital Ocean knows on behalf of whom API calls are made (and so he can identify the account/user that will be billed ;)).</li><li>DIGITALOCEAN_IMAGE: This is indicates which Linux Distro/OS we want to run on the server. We went here for Debian 8 since Multi-Host networking requires a kernel &gt;= 3.16.</li><li>DIGITALOCEAN_PRIVATE_NETWORKING: This enables communication between servers on the same data-center using a private network (i.e this network is not visible/accessible to the “outside” world). Take a look <a href="https://www.digitalocean.com/company/blog/introducing-private-networking/">here</a> if you want to learn more about Digital Ocean’s private networking feature.</li><li>DIGITALOCEAN_REGION: This is the region where servers will be created. I went for the Frisco region because is located in North America, but feel free to choose a different one especially if it happens to be closer to your geographical location. For a list of available regions take a look at the Digital Ocean’s <a href="https://developers.digitalocean.com/documentation/v2/#regions">regions API</a></li><li>DIGITALOCEAN_SIZE: This is the amount of RAM to be allocated for the server. Even though you can go for 512mb which is less expensive I strongly suggest that you use 1gb since the price difference is not that significant and you will certainly appreciate the performance gain.</li></ul><p>For a comprehensive list of available options related the Digital Ocean driver for Docker machine take a look at the <a href="https://docs.docker.com/machine/drivers/digital-ocean/">online documentation</a></p><p>Swarm requires access to a <a href="https://en.wikipedia.org/wiki/Key-value_database">Key-Value store</a> so that nodes can be discovered and added tot he cluster (or removed when the node goes down). So let’s launch a server for the sole purpose of running the Key Value store, which in our case will be <a href="https://www.consul.io/">Consul</a>:</p><pre>$ docker-machine create -d digitalocean kvstore<br>$ eval $(docker-machine env kvstore)<br>$ export KV_IP=$(docker-machine ssh kvstore &#39;ifconfig eth1 | grep &quot;inet addr:&quot; | cut -d: -f2 | cut -d&quot; &quot; -f1&#39;)<br>$ docker run -d -p ${KV_IP}:8500:8500 -h consul--restart=always progrium/consul -server -bootstrap</pre><p>wait a few minutes for the machine to come online and make sure the Consul sever is up and running by running:</p><pre>docker-machine ssh kvstore curl -I <a href="http://$kv_ip:8500/">http://$KV_IP:8500</a>  2&gt;/dev/null</pre><p>which should produce an output like this:</p><pre>HTTP/1.1 301 Moved Permanently<br>Location: /ui/<br>Date: Tue, 19 Jan 2016 04:48:34 GMT<br>Content-Type: text/plain; charset=utf-8</pre><p>With the Key Value store in place lets launch the Swarm master:</p><pre>docker-machine create -d digitalocean --swarm  --swarm-master --swarm-discovery=&quot;consul://${KV_IP}:8500&quot; --engine-opt=&quot;cluster-store=consul://${KV_IP}:8500&quot;  --engine-opt=&quot;cluster-advertise=eth1:2376&quot;  swarm-master</pre><p>and now lets summon those minions:</p><pre>$ export NUM_WORKERS=3<br>$ for i in $(seq 1 $NUM_WORKERS); do <br>docker-machine create -d digitalocean --digitalocean-size=1gb --swarm --swarm-discovery=&quot;consul://${KV_IP}:8500&quot; --engine-opt=&quot;cluster-store=consul://${KV_IP}:8500&quot; --engine-opt=&quot;cluster-advertise=eth1:2376&quot; swarm-node-${i} &amp;<br>done;</pre><p>This operation should take about 10–15 mins, so go grab a cup of coffee ;).</p><p>I know there is quite a bit to digest here, but if you find it overwhelming please do take the time to read <a href="http://nathanleclaire.com/blog/2015/11/17/seamless-docker-multihost-overlay-networking-on-digitalocean-with-machine-swarm-and-compose-ft.-rethinkdb/">Nathan’s post</a> and I’m sure by the time you’re done everything in this article will make perfect sense.</p><h3>The Elasticsearch Cluster</h3><p>With our infrastructure cluster in place we can now focus on the fun stuff: creating an Elasticsearch cluster. But before that, let’s take a very quick look at Elasticsearch (ES from now on). ES is a high-availability/multi-tenant full-text search sever based on <a href="https://lucene.apache.org/core/">Lucene</a>. Yes, I know that was a mouthful to say but take a couple of minutes at the <a href="https://www.elastic.co/products/elasticsearch">ES home page</a> and you’ll get a better idea of what this remarkable piece of software can do for you.</p><p>It might seem a bit late, but there is one question I’d like to address before moving on. Why an ES Cluster? Aren’t there a few cloud solutions already available at affordable prices? Yes there are some, like <a href="https://aws.amazon.com/elasticsearch-service/">Amazon Elastic Search </a>and <a href="https://qbox.io/">QBox</a>. but you still need at least $50 if you want a decent setup. Yes, it is true that Amazon Elastic Search is cloud based and that you pay only for what you use but it takes some time to get use to Amazon’s terms and concepts (and the interface, and the lots of clicks ;))</p><p>There is also another reason why I think being able to run an ES cluster of your own can save you some time and money. A few months ago I was tasked to evaluate a suitable <a href="http://microservices.io/patterns/apigateway.html">API Gateway</a> to be put in front of our HTTP API(s). After a few weeks testing solutions from major providers it was clear to me that <a href="https://getkong.org/">Kong</a> would suit our needs to a large degree. I won’t go into the details as to why Kong is such a good solution but if you’re in the business of API(s) and Micro Services do take a look at it. So, once it was clear that Kong was the way to go, I needed to be sure that we wouldn’t incur into any performance penalties once we started routing API calls through the Kong API Gateway. To make the story short, I ended up creating a small Python script to be able to replay API calls from logs files and <a href="https://github.com/yoanisgil/locust-grafana">this</a>.</p><p>That little projet of mine integrates <a href="http://locust.io/">Locust</a>, <a href="https://github.com/etsy/statsd">Statsd</a>, <a href="http://grafana.org/">Grafana</a> and <a href="https://github.com/influxdata/influxdb">InfluxDB</a> in order to visualize in real time the number of requests a given site/URL can handle over a short period of time. It is mostly about gluing all those pieces of software into a reusable stack and of course with a lot of help from Docker and Docker Compose. If I had only know ES around that time it would have saved me <strong>a lot</strong> of time. Why? You will see in no time.</p><p>So, time to launch the ES cluster. Grab this <a href="https://gist.github.com/yoanisgil/047256dbe21622c1a10a">docker-compose file</a> and save it somewhere in your filesystem.:</p><pre>$ mkdir -p ~/tmp/es-cluster<br>$ cd ~/tmp/es-cluster<br>$ curl <a href="https://gist.githubusercontent.com/yoanisgil/047256dbe21622c1a10a/raw/51a35962ed06d327c9f780fca6a8a05b522d9c70/docker-compose.yml">https://gist.githubusercontent.com/yoanisgil/047256dbe21622c1a10a/raw/51a35962ed06d327c9f780fca6a8a05b522d9c70/docker-compose.yml</a> &gt; docker-compose.yml</pre><p>with the file saved, lets make sure newly launched containers will run on our recently created Swarm cluster:</p><pre>$ eval $(docker-machine env --swarm swarm-master)</pre><p>and we can confirm that nodes are ready for taking work, by running:</p><pre>$ docker info<br>Containers: 5<br>Images: 4<br>Role: primary<br>Strategy: spread<br>Filters: health, port, dependency, affinity, constraint<br>Nodes: 4<br> swarm-master: 107.170.200.211:2376<br>  └ Status: Healthy<br>  └ Containers: 2<br>  └ Reserved CPUs: 0 / 1<br>  └ Reserved Memory: 0 B / 1.026 GiB<br>  └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), provider=digitalocean, storagedriver=aufs<br> swarm-node-1: 107.170.203.99:2376<br>  └ Status: Healthy<br>  └ Containers: 1<br>  └ Reserved CPUs: 0 / 1<br>  └ Reserved Memory: 0 B / 1.026 GiB<br>  └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), provider=digitalocean, storagedriver=aufs<br> swarm-node-2: 107.170.194.118:2376<br>  └ Status: Healthy<br>  └ Containers: 1<br>  └ Reserved CPUs: 0 / 1<br>  └ Reserved Memory: 0 B / 1.026 GiB<br>  └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), provider=digitalocean, storagedriver=aufs<br> swarm-node-3: 107.170.247.233:2376<br>  └ Status: Healthy<br>  └ Containers: 1<br>  └ Reserved CPUs: 0 / 1<br>  └ Reserved Memory: 0 B / 1.026 GiB<br>  └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), provider=digitalocean, storagedriver=aufs<br>CPUs: 4<br>Total Memory: 4.103 GiB<br>Name: 6546401664f0</pre><p>and here comes the fun. First we will launch a ES master node:</p><pre>docker-compose --x-networking --x-network-driver overlay up -d master</pre><p>The Docker Compose service relavant to this command looks like this:</p><pre>master:<br>    image: elasticsearch:2<br>    ports:<br>       -&quot;9200:9200&quot;<br>    restart: always<br>    container_name: es_master</pre><p>Most of these options will look familiar to you and I know providing a <em>container_name</em> reduces to 1 the number of containers with the same name that can run on a Swarm node but this will make things a bit easier for running certain actions on the ES master node later on.</p><p>The <em>es_master</em> container will act as an contact/entry point for the other nodes to know about the cluster topology. Before we launch more nodes let’s install the <a href="https://github.com/royrusso/elasticsearch-HQ">Elasticsearch-HQ plugin</a>, a plugin that will provide us with some very useful monitoring/configuration details about the cluster:</p><pre>docker exec es_master plugin install royrusso/elasticsearch-HQ</pre><p>Once the plugin has been installed lets take a look at what sort of information you can get from it. Run this command:</p><pre>$ echo &quot;http://$(docker inspect --format=&#39;{{(index (index .NetworkSettings.Ports &quot;9200/tcp&quot;) 0).HostIp}}&#39; es_master):9200/_plugin/hq/&quot;</pre><p>grab the resulting URL and enter it on your browser. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NeNJPQEr7N-X6uNl.png" /></figure><p>and, as the screenshot indicates, do not forget to click the <strong>Connect</strong> button when the page loads for the first time.</p><p>We can clearly see that we have 1 node running, so let’s launch 3 more:</p><pre>docker-compose --x-networking --x-network-driver overlay scale es-node=3</pre><p>and this is it! It does not get any easier like these. We have requested Docker Compose to summon 3 containers, each one of them running ES and by specifying <strong>–x-networking –x-network-driver overlay</strong> they will all be connected and reachable within a private network of their own. This all works of course because we’re running Docker 1.9 on top of Swarm. Let’s take a look at the section of the Docker Compose file which takes care of defining the ES nodes:</p><pre>es-node:<br>  image: elasticsearch:2<br>  command: elasticsearch --discovery.zen.ping.unicast.hosts=es_master<br>  restart: always<br>  environment:<br>    -&quot;affinity:container!=*master*&quot;<br>    -&quot;affinity:container!=*es-node*&quot;</pre><p>There are two important pieces here:</p><ul><li><strong>discovery.zen.ping.unicast.hosts=es_master</strong>: We’re instructing ES to use <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery-zen.html">Zen Discovery</a> in order to find out the cluster topology. We’re telling nodes to contact the <em>es_master</em> host as the entry point for the gossiping protocol. Notice that <em>es_master</em> is the name we gave to our container running the ES master node.</li><li><strong>-“affinity:container!=<em>master</em>”</strong> / “<strong>affinity:container!=<em>es-node</em>”</strong>: We’re instructing Swarm to make sure that ES containers cannot run where the ES master container is running and that we only want to run one ES node per Swarm node.</li></ul><p>So let’s go back and take a look at HQ plugin page. It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PsO_4XVHzHQ02wbl.png" /></figure><p>Finally, lets launch a Kibana container which is able to connect to our ES cluster. First open the<em>docker-compose.yml</em> file, look for the string <strong>ES_MASTER_IP</strong> and replace it with the IP address of the ES master node. You can get the IP address by running:</p><pre>docker inspect --format=&#39;{{(index (index .NetworkSettings.Ports &quot;9200/tcp&quot;) 0).HostIp}}&#39; es_master</pre><p>With that done, we can launch a Kibana container:</p><pre>docker-compose --x-networking --x-network-driver overlay up -d kibana</pre><p>and then go grab the URL where Kibana is running and enter it in our browser:</p><pre>echo &quot;http://$(docker inspect --format=&#39;{{(index (index .NetworkSettings.Ports &quot;5601/tcp&quot;) 0).HostIp}}&#39; kibana):5601&quot;</pre><p>you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rc6iLmdDuZCHP8qE.png" /></figure><p>And that’s it! You can start using your ES cluster with <a href="https://www.elastic.co/products/logstash">Logstash</a>/<a href="https://www.elastic.co/products/beats/filebeat">Filebeat</a>. Just make sure you properly configure the <a href="https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html">elastic search output plugin</a> and make it point to the ES master node (any other node from the cluster will do as well).</p><p>Go ahead and have fun! Try adding new nodes, removing existing ones and see it all in action.</p><p>And, hey!, do not forget to turn those servers off because you know, you’re billed as long as they’re running ;). You can do that with docker-machine:</p><pre>$ docker-machine rm kvstore swarm-master swarm-node-1 swarm-node-2 swarm-node-3</pre><h3>Finito</h3><p>By now it should be clear to you how easy it is to run a Elasticsearch cluster on a cloud provider of your own. Moreover you have full control of how and when this is done. I’m not saying that by following the instructions provided here you will end up with a production grade cluster. This is far from it. However, for short lived task, like real time data analysis for making short term decisions I believe this presents some very interesting and unique options (and challenges as well).</p><p>One thing I did not cover in this article was data persistence. That’s certainly something to keep in mind if you need data to stick around after the life cycle of your cluster. I must be honest and say that I tried to achieve that by using <a href="https://github.com/libopenstorage/openstorage">Openstorage</a> but unfortunately I ran into <a href="https://github.com/libopenstorage/openstorage/issues/109">this issue</a>. I will try to follow up on that and see if I can finally get data persistence working within a Swarm cluster but that will go for sure into another blogpost ;).</p><p>For those asking themselves why ES would have saved me a lot of time, the answer it’s easy: I only needed to log any performance information to a location (file, syslog, etc) which Logstash/Filebeast knows how to read. The rest was about getting ES to index the information and spent some time toying around with Kibana for producing the reports/graphs I needed.</p><h3>Big Thanks</h3><p>Yes, that’s absolutely something I need to do. Here it goes in no particular order of priority:</p><ul><li>To Nathan Leclaire for his <a href="http://nathanleclaire.com/blog/2015/11/17/seamless-docker-multihost-overlay-networking-on-digitalocean-with-machine-swarm-and-compose-ft.-rethinkdb/">excellent post</a>. Can thank you enough mate, your post the starting point.</li><li>To Elasticsearch for crafting such a magic piece of software.</li><li>To Roy Russo for his excellent ElasticSearch HQ plugin.</li><li>To Docker and I think we’all know why :).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efabe110c675" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging with Docker — Part 1.1]]></title>
            <link>https://medium.com/@yoanis_gil/logging-with-docker-part-1-1-965cb5e17165?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/965cb5e17165</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Thu, 24 Dec 2015 18:58:41 GMT</pubDate>
            <atom:updated>2015-12-24T22:52:53.227Z</atom:updated>
            <content:encoded><![CDATA[<p>So it’s been a while since <a href="https://medium.com/@yoanis_gil/logging-with-docker-part-1-b23ef1443aac">I started this blog series on logging with Docker</a> and though I said the next article will be about <em>gelf</em> and <em>fluentd</em>, I wanted to take the time to provide a more realistic example which illustrates what it takes to integrate logging into your web application. Because let’s face it, this:</p><pre><strong>import</strong> sys<br><strong>import</strong> time</pre><pre><strong>while</strong> <strong>True</strong>:<br>    sys.stderr.write(&#39;Error\n&#39;)<br>    sys.stdout.write(&#39;All Good\n&#39;)<br>    time.sleep(1)</pre><p>hardly counts as an application, nor you get paid for writing such code ;). That said we will create a very simple <a href="http://flask.pocoo.org/">Flask</a> application for creating <a href="https://en.wikipedia.org/wiki/Countdown">Countdowns</a>. The application code is already hosted on<a href="https://github.com/yoanisgil/countdown-python">GitHub</a></p><p>The examples given throughout the article were created and tested using Docker v1.9.</p><h3>Quick Recap: Docker logging 101</h3><p>How logging works:</p><ul><li>Anything your application write to it’s stdin/stderr will be shipped to the configured driver</li><li>Logging driver can be globally configured at the Docker daemon level, when launching it.</li><li>When creating a new container one can specify the logging driver to be used, which effectively overrides de daemon’s configuration.</li></ul><p>As of Docker 1.9 there are 6 logging drivers implementations:</p><ul><li>json-file: This is the default driver. Everything gets logged to a JSON-structured file</li><li>syslog: Ship logging information to a syslog server</li><li>journald: Write log messages to journald (journald is a logging service which comes with<a href="http://www.freedesktop.org/wiki/Software/systemd/">systemd</a>)</li><li>gelf: Writes log messages to a <a href="https://www.graylog.org/resources/gelf/">GELF</a> endpoint like Graylog or Logstash</li><li>fluentd: Write log messages to <a href="http://www.fluentd.org/">fluentd</a></li><li>awslogs: <a href="https://aws.amazon.com/about-aws/whats-new/2014/07/10/introducing-amazon-cloudwatch-logs/">Amazon CloudWatch Logs</a> logging driver for Docker</li></ul><h3>The Application</h3><p>As stated before we will be using a countdown application for illustration purposes. The application is quite simple itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yAVsCbQjjZlvtrPR.png" /></figure><p>after providing a description for tracking down the time to your must beloved and anxiously awaited event you will be presented with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uXP89D_HadqRax0j.png" /></figure><p>Simple right? So let’s get to work and break this thing in pieces.</p><h3>Docker … always Docker</h3><p>As you might have already guessed this application was developed to work 100% with Docker so a <a href="https://github.com/yoanisgil/countdown-python/blob/master/Dockerfile">Dockerfile</a> has been created for that matter, which allows running a Python <a href="https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface">WSGI application</a> using <a href="https://www.nginx.com/">Nginx</a> and <a href="https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface">Gunicorn</a>. The file itself it’s a quite a piece of work and it probably deserves it’s own post (<strong>NOTE to self</strong>: Lets blog about it!). It’s exactly 42 lines, I swear it was not my intention to do it like that, and it takes care of:</p><ul><li>Installing Nginx.</li><li>Installing application dependencies from requirements.txt.</li><li>Providing a default Nginx site configuration which makes Nginx and Gunicorn work together.</li><li>Providing a set of utility scripts to be able to launch the application from Gunicorn.</li><li>Configure Supervisord to launch Nginx and Gunicorn.</li></ul><p>If you take a closer look at the Dockerfile you will notice that the application entry point looks like this:</p><pre>CMD [&quot;supervisord&quot;, &quot;-n&quot;, &quot;-c&quot;, &quot;/etc/supervisord/supervisord.conf&quot;]</pre><p>and this is because we’re using <a href="http://supervisord.org/">Supervisord</a>, a process control system, which acts as the <a href="https://en.wikipedia.org/wiki/Init">Init Process</a>. If you’re wondering why a process control system like Supervisord is required, please take a look at this <a href="https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/">excellent article</a> which explains the PID 1 zombie reaping problem. It&#39;s also of great value if you run multiple daemons inside your container.</p><p>Let&#39;s take a look at the life cycle of incoming requests to the application. Each HTTP request will follow the path below :</p><p>HTTP Request &lt; → Nginx &lt;– Proxy Pass –&gt; Gunicorn &lt;– WSGI –&gt; Flask Application</p><p>As we already know, the application needs to send all logging statements to it’s stdin/stderr output but bear in mind that Docker will only collect the output from the process with ID 1. That said a few tweaks are required to Supervisord, Nginx and Gunicorn so that logging statements are transparently captured. Let’s go over them.</p><h3>Supervisord configuration</h3><p>Since we’re using Supervisord to launch our application, this is where the Docker daemon will be collecting information from . We need to make sure that everything that get sends to Gunicorn/Nginx stdin/stderr output it&#39;s actually logged to Supervisord’s stdin/stderr. Below the relevant pieces of configuration:</p><pre><strong>[program:gunicorn]</strong><br>command=/usr/local/bin/gunicorn_start.sh<br><strong>stdout_logfile=/dev/stdout</strong><br>stdout_logfile_maxbytes=0<br><strong>stderr_logfile=/dev/stderr</strong><br>stderr_logfile_maxbytes=0</pre><pre><strong>[program:nginx]</strong><br>command=/usr/sbin/nginx<br><strong>stdout_logfile=/dev/stdout</strong><br>stdout_logfile_maxbytes=0<br><strong>stderr_logfile=/dev/stderr</strong><br>stderr_logfile_maxbytes=0</pre><p>The important bit of config here is <strong>stdout_logfile=/dev/stdout</strong> and <strong>stderr_logfile=/dev/stderr </strong>since it instructs Supervisord to capture processes stdin/stderr output and forward it to Supervisord&#39;s stdin/stderr, which in turn will be collected by the Docker daemon and shipped to the configured logging driver.</p><h3>Nginx/Gunicorn configuration</h3><p>Since supervisord collects stdin/stderr from the processes it controls we need to instruct them to log everything to the expected descriptors. Bellow the relevants pieces of configuration for Nginx and Gunicorn:</p><h4>Nginx configuration</h4><pre>error_log /dev/stderr info;<br>daemon off;</pre><pre>events {<br>    worker_connections  1024;<br>}</pre><pre>http {<br>    <strong>...</strong><br>    access_log  /dev/stdout main;<br>    ....<br>}</pre><h4>Gunicorn configuration</h4><pre>exec gunicorn ${WSGI_MODULE}:${WSGI_APP} \<br>  --name $NAME \<br>  --workers $NUM_WORKERS \<br>  --user=$USER --group=$GROUP \<br>  --bind=unix:$SOCKFILE \<br>  --log-level=info \<br>  --log-file=/dev/stdout</pre><h3>Logging (finally)</h3><p>With all the little pieces of configuration described above we can finally focus on logging from an application point of view. As an example I’ve added a logging statement for each 404 error on the website:</p><pre>@app.route(&#39;/v/&lt;int:countdown_id&gt;&#39;)<br><strong>def</strong> <strong>countdown</strong>(countdown_id):<br>    count_down = Countdown.query.filter_by(id=countdown_id).first()</pre><pre>    <strong>if</strong> <strong>not</strong> count_down:<br>        app.logger.error(&#39;404 on countdown with id %s&#39; % countdown_id)<br>        <strong>return</strong> render_template(&#39;404.html&#39;, countdown_id=countdown_id), 404</pre><pre>    <strong>return</strong> render_template(&#39;countdown.html&#39;, countdown=count_down)</pre><p>At this point it’s really up to you to configure your Framework’s logging handlers and make sure they log to stdin/stderr. In the case of Flask application there is already a logger object, which is a standard Python <a href="https://docs.python.org/2/library/logging.html">Logger object</a>.</p><p>Back to our Countdown application, let’s see it in action. To make things easier, I&#39;ve crafted a Docker Compose file which will take care of building and running the application. After you clone <a href="https://github.com/yoanisgil/countdown-python">the repo</a> and before you launch the application make sure you edit the docker-compose.yml file and change the value of <strong>syslog-address</strong> to match your Docker setup. For instance if you’re running Docker on OS X with Machine then you need to update this <strong>syslog-address: “udp://192.168.99.101:5514”</strong> to use the IP address of your virtual machine. With that in mind, let’s launch the application:</p><pre>$ docker-compose build countdown # Build the application image<br>$ docker-compose up -d countdown<br>$ docker <strong>exec</strong>  rsyslog tail -f /var/log/messages</pre><p>and then visit <a href="http://localhost:5000/">http://localhost:5000</a> and you should see the application welcome page. Let’s force a 404 error by visiting <a href="http://dockerhost:5000/v/42">http://dockerhost:5000/v/42</a>. Go back to the console where the docker execcommand was launched and you should see something like this:</p><pre>2015-12-24T04:35:45Z <strong>default</strong> docker/countdown[1012]: -----------<br>2015-12-24T04:35:45Z <strong>default</strong> docker/countdown[1012]: ERROR in app [/srv/app/app.py:102]:<br>2015-12-24T04:35:45Z <strong>default</strong> docker/countdown[1012]: 404 on countdown with id 42<br>2015-12-24T04:35:45Z <strong>default</strong> docker/countdown[1012]: -----------<br>2015-12-24T04:35:45Z <strong>default</strong> docker/countdown[1012]: 192.168.99.1 - - [24/Dec/2015:04:35:45 +0000] &quot;GET /v/42 HTTP/1.1&quot; 404 394 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10<strong>_10_5</strong>) AppleWebKit/537.36 (KHTML, <strong>like</strong> Gecko) Chrome/47.0.2526.106 Safari/537.36&quot; &quot;-&quot;</pre><p>which shows a log statement from the application and from Nginx as well. How was this possible? Let’s take a look at the <a href="https://github.com/yoanisgil/countdown-python/blob/master/docker-compose.yml">Docker compose file</a>:</p><pre>countdown:<br>    build: . <br>    environment:<br>        - NUM_WORKERS=1<br>        - APP_NAME=countdown<br>        - WSGI_MODULE=app<br>        - WSGI_APP=app<br>        - PYTHONPATH=/srv/app<br>        - APP_LISTEN_ON=0.0.0.0<br>        - APP_DEBUG=True<br>        - PYTHONUNBUFFERED=1<br>        - DB_DIR=/var/lib/countdown<br>    ports:<br>        - &quot;5000:80/tcp&quot;<br>    volumes:<br>        - ./data:/var/lib/countdown<br>    links:<br>        - syslog<br>    log_driver: syslog<br>    log_opt: <br>        syslog-address: &quot;udp://192.168.99.101:5514&quot;<br>        syslog-tag: &quot;countdown&quot;<br>syslog:<br>    image: voxxit/rsyslog <br>    ports:<br>        - &quot;5514:514/udp&quot;<br>    container_name: rsyslog</pre><p>As you can see we’re linking the container powering the Countdown application with the syslog container. This is not strictly required since it’s the Docker daemon who takes care of forwarding logging output towards the syslog container, but it guarantees that the Syslog container is always started as a dependency of our application. The rest is the same, as it was covered on Part 1, we configure our container to use the <strong>syslog</strong> driver and we make sure to add a tag.</p><h3>What’s next?</h3><p>By now you should have a better idea about how to effectively let Docker capture your logging information without prior knowledge of your application architecture and have it send to a configurable backend.</p><p>The reason I like this approach is because of the degree of freedom it gives to both developers and sysadmins. Logging to stdin/stderr during the development process is a breeze since you don’t need to tail/grep files located elsewhere. From a sysadmin/operations point of view it allows to easily configure how logging statements are archived, their destination, etc and most importantly without the need of performing any application specific configuration.</p><p>On the next article of these series I will finally approaching the <em>fluentd, gelf</em> and <em>awslogs </em>drivers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=965cb5e17165" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sensaciones de un fan sobre El Clásico 21/11/2015]]></title>
            <link>https://medium.com/@yoanis_gil/sensaciones-de-un-fan-sobre-el-cl%C3%A1sico-21-11-2015-81f4b43bef6a?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/81f4b43bef6a</guid>
            <category><![CDATA[real-madrid]]></category>
            <category><![CDATA[futbol]]></category>
            <category><![CDATA[barcelona]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Sat, 21 Nov 2015 21:10:20 GMT</pubDate>
            <atom:updated>2015-11-21T21:10:20.718Z</atom:updated>
            <content:encoded><![CDATA[<p>Se terminó. Después de un año esperando por E<a href="https://en.wikipedia.org/wiki/El_Cl%C3%A1sico">l Clásico</a>, finalmente llegó y para cualquier fan del Real Madrid no terminó de la manera que hubiésemos querido. Es de humanos sentirse triste después de ver a tu equipo perder contra su eterno rival y por supuesto no es nada gratificante. De cualquier manera nada de esto explica el motivo de este artículo.</p><p>Además de tristeza, siento <strong>DECEPCIÓN</strong> e <strong>IMPOTENCIA</strong>. He visto al Real Madrid perder no pocas veces ante el Barcelona, pero en ninguna ocasión se sintió así. Teníamos nuestro mejor equipo en la cancha. Algunos podrían esgrimir que Dani Carvajal debió ser titular por encima de Danilo, o que Casemiro debió formar parte del once inicial en sustitución de Gareth Bale, Toni Kroos o del mismísimo Luka Modric. Pero nada de esto importa, porque todos estos jugadores, incluyendo aquellos que se encontraban en el banco, forman parte de lo mejor y más grande del fútbol a nivel mundial.</p><p>Desde que el partido acabó, y un poco antes también, llevo pensando en el motivo de estos sentimientos. Para ser honesto, todavía no tengo una explicación precisa, pero aquí van algunas ideas:</p><ul><li>Por qué James Rodríguez tuvo que ser el primer jugador en ser sustituido?</li><li>Donde estuvo Gareth Bale durante todo el partido? Su falta de implicación y sobre todo su apatía total terminó acabando conmigo. Personalmente pienso que este partido fueron 10 contra 11.</li><li>Como es posible que tras ir perdiendo 0–2 al final de la primera mitad, Rafael Benitez no haya realizado ninguna modificación al once inicial?</li></ul><p>Estoy seguro que este juego dará mucho de que hablar durante los próximos días, y que los expertos del deporte encontrarán magníficas teorías que expliquen la debacle del Real Madrid. Personalmente pienso que fuimos superados por el Barcelona en todos los planos y etapas del juego. Así de simple.</p><p>Y sí, me siento impotente al saber que no hay nada que los fans podamos hacer para revertir esta situación. Siempre he estado orgulloso de la casta del Real Madrid, de su deseo insaciable de ganar todos los juegos aún y cuando todo esté en contra. Esto fue lo que nos enseñó jugadores como Raúl González y Don Alfredo Di Stefano. Este es legado de Don Santiago Bernabéu. Y lo estamos tirando a la basura con personas como Rafael Benitez, Gareth Bale … y sí, Florentino Perez inclúyete en esa lista también.</p><p>Hala Madrid y nada más!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81f4b43bef6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A word from a fan on El Clásico 21/11/2015]]></title>
            <link>https://medium.com/@yoanis_gil/a-word-from-a-fan-on-el-cl%C3%A1sico-21-11-2015-3656a21ad96a?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3656a21ad96a</guid>
            <category><![CDATA[madrid]]></category>
            <category><![CDATA[barcelona]]></category>
            <category><![CDATA[soccer]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Sat, 21 Nov 2015 20:30:53 GMT</pubDate>
            <atom:updated>2015-11-21T21:08:33.208Z</atom:updated>
            <content:encoded><![CDATA[<p>It&#39;s over. After a year waiting for E<a href="https://en.wikipedia.org/wiki/El_Cl%C3%A1sico">l Clásico</a>, it finally arrived and for any loyal Real Madrid fan it did not end as we all would have wanted to. I think it&#39;s only human and natural to feel sad because watching your team loose to your arch-enemy is not the most satisfying thing ever. But, this is not the reason I&#39;m writing these few words.</p><p>Aside from feeling sad, I feel <strong>DISAPPOINTED and HELPLESS. </strong>I have witnessed Real Madrid loose quite a few times to Barcelona but it never felt like this. We had our best possible team on the pitch. One could argue that Dani Carvajal had all the right to be part of the starting eleven, or that it should have been Casemiro over Gareth Bale, Toni Kroos or Luka Modric. But none of this matters, because all of those players, including the subs, are among the finest and greatest of the football world.</p><p>I had been banging my head against the wall looking for a reason explaining <strong>why</strong> I do I feel the way I do. I haven&#39;t figured out yet, but here are few things which will keep me thinking for the rest of the week:</p><ul><li>Why did James Rodríguez had to be the first player to go to the bench?</li><li>Where was Gareth Bale throughout the entire game? His lack of motivation just killed me. He was never involved in the game. I felt like we were playing 10 Vs 11.</li><li>How come we&#39;re loosing 0–2 by the end of the first time and Rafael Benitez didn&#39;t have the courage to modify the starting eleven?</li></ul><p>Much and more will be said about this game, and I&#39;m sure sports experts will provide us with sound theories about what when bad and wrong. Personally I just think we were out-bested by Barcelona from the very beginning.</p><p>And yes, I feel helpless knowing that there is nothing we, the fans, can do to change this situation. I&#39;ve been always pride of Real Madrid&#39;s unstoppable desire to win a game, no matter the odds. This is what players like Raúl González and Don Alfredo Di Stefano taught us. This the legacy Don Santiago Bernabéu left us. And we&#39;re throwing it away because of people like Rafael Benitez, Gareth Bale … and, yes, Florentino Pérez add yourself to that list too.</p><p>Hala Madrid y nada más!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3656a21ad96a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging with Docker — Part 1]]></title>
            <link>https://medium.com/@yoanis_gil/logging-with-docker-part-1-b23ef1443aac?source=rss-690c49c01fa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b23ef1443aac</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[Yoanis Gil Delgado]]></dc:creator>
            <pubDate>Wed, 16 Sep 2015 02:40:12 GMT</pubDate>
            <atom:updated>2015-09-18T12:23:29.830Z</atom:updated>
            <content:encoded><![CDATA[<h2>Introduction</h2><p>Logging is a central piece to almost every application. It is one of those things you want to keep around specially when things go wrong. Much and more have been say and done on this particular subject, however, today I want to focus on <a href="http://www.docker.com/">Docker</a> and the options available when it comes to logging in the context of containerized application. Logging capabilities available in the Docker project are exposed in the form of drivers, which is very handy since one gets to choose how and where log messages should be shipped. As of the moment of writing this article there are five of them:</p><ul><li>json-file: This is the default driver. Everything gets logged to a JSON-structured file</li><li>syslog: Ship logging information to a syslog server</li><li>journald: Write log messages to journald (journald is a logging service which comes with <a href="http://www.freedesktop.org/wiki/Software/systemd/">systemd</a>)</li><li>gelf: Writes log messages to a <a href="https://www.graylog.org/resources/gelf/">GELF</a> endpoint like Graylog or Logstash</li><li>fluentd: Write log messages to <a href="http://www.fluentd.org/">fluentd</a></li></ul><p>This article is the first of a few ones centered around logging in Docker. We will take a rather in-depth look to the first two drivers <em>json-file</em> and <em>syslog</em>. We will see how they work and what their strengths and limitations are, etc.</p><p>The examples given throughout the article were created and tested using Docker v1.8 which introduces the gelf and fluentd drivers alone with a few nice additions to the syslog one (tagging, logging facility, etc). You can read more about it <a href="https://github.com/docker/docker/blob/v1.8.1/CHANGELOG.md#180-2015-08-11">here</a>.</p><p><strong>NOTE</strong>: This article’s source code alone with the code used can be found on <a href="https://github.com/yoanisgil/docker-logging-tutorial">Github</a></p><h2>Docker Logging 101</h2><p>Before getting into the specifics of any of the available logging drivers, there are these questions you might have already asked yourself:</p><ul><li>What messages are actually logged?</li><li>How do I get my messages shipped to the logging driver?</li></ul><p>The answer to first question it’s actually dead easy: anything that gets written out to the container’s standard output/error will get logged. As to the answer to the second one, you don’t need to do much, at least not by default. When a new container is created, and provided that no logging specific options were passed at the moment of creating it, the docker engine will configure the default logging driver which is the json-file one. So if we put together 1 and 2 it’s clear that anything your application write to it’s standard output/error will get written in a json file. That simple.</p><p>Ok, that last one paragraph was too long, so enough wording and let’s see it in action. First we will create a simple python script which writes to both it’s stdout and stderr output:</p><pre><strong>import</strong> sys  <br> <strong>import</strong> time  </pre><pre> <strong>while</strong> <strong>True</strong>:  <br>   sys.stderr.write(&#39;Error\n&#39;)  <br>   sys.stdout.write(&#39;All Good\n&#39;)  <br>   time.sleep(1)</pre><p>Save this to a file logging-01.py (or you can get it from <a href="https://stackedit.io/logging-01.py">here</a>) and then run:</p><pre>$ docker run --name logging-01 -t -d -v $(pwd):/tmp  -w /tmp python:2.7 python -u logging-01.py<br>$ docker logs -f logging-01</pre><p>which will output:</p><pre>Error<br>All Good<br>Error<br>All Good</pre><p>This illustrates how messages written to stdout/stderr are logged and it’s actually available with the docker logs command. But wait, isn’t this the json-file driver? So where is this so called JSON file? Let’s inspect our container and see what we can find:</p><pre>$ docker inspect logging-01 | grep LogPath<br>    &quot;LogPath&quot;: &quot;/mnt/sda1/var/lib/docker/containers/ae1629aceb0b82da6451a981d073243bf7374c07634a377c64a9a7fcea2b40e1/ae1629aceb0b82da6451a981d073243bf7374c07634a377c64a9a7fcea2b40e1-json.log&quot;,</pre><p>you will get a different output from the command above but the important thing here is that we have the path to the file where our log messages are written to. Let’s take a look at this file:</p><pre>tail -2 /mnt/sda1/var/lib/docker/containers/ae1629aceb0b82da6451a981d073243bf7374c07634a377c64a9a7fcea2b40e1/ae1629aceb0b82da6451a981d073243bf7374c07634a377c64a9a7fcea2b40e1-json.log<br>{&quot;log&quot;:&quot;Error\r\n&quot;,&quot;stream&quot;:&quot;stderr&quot;,&quot;time&quot;:&quot;2015-09-13T03:36:30.120234597Z&quot;}<br>{&quot;log&quot;:&quot;All Good\r\n&quot;,&quot;stream&quot;:&quot;stdout&quot;,&quot;time&quot;:&quot;2015-09-13T03:36:30.120475567Z&quot;}</pre><p>which is self-explanatory me thinks ;). The json-file driver takes two more options:</p><ul><li>–log-opt max-size=[0–9+][k|m|g]</li><li>–log-opt max-file=[0–9+]</li></ul><p>about which you can know more <a href="https://docs.docker.com/reference/logging/overview/">here</a>. These options lets you control the rate at which log files are allowed to grow. To illustrate this lets re-run our little application:</p><pre>$ docker run --rm --log-opt max-file=2  --log-opt max-size=2k  --name logging-02 -v $(pwd):/tmp  -w /tmp python:2.7 python -u logging-01.py<br>Error<br>All Good<br>Error<br>All Good<br>....</pre><p>here we have indicated that we only want to keep 2 log files and the max allowed size for any given log file is 2k. You can verify that this is indeed happening by grabbing the location of the default log file:</p><pre>$ docker inspect logging-02 | grep LogPath<br>       &quot;LogPath&quot;:&quot;/mnt/sda1/var/lib/docker/containers/04a96c05121777eebe6a38d63fd657f6fb6c8b9632fee7d81ccc0ff45023aedd/04a96c05121777eebe6a38d63fd657f6fb6c8b9632fee7d81ccc0ff45023aedd-json.log&quot;,<br>$ cd /mnt/sda1/var/lib/docker/containers/04a96c05121777eebe6a38d63fd657f6fb6c8b9632fee7d81ccc0ff45023aedd/<br>$ watch &#39;ls -lh *json*&#39;</pre><h2>The Syslog driver</h2><p>The json-file driver is as simple as it gets and while it’s very useful for development purposes but it won’t do the job once the list of running containers starts to growth. This is not strictly related to performance issues but rather to the fact that as the number of containers and applications starts to increase it becomes a no men work to track logging information. Enter the syslog driver.</p><p>This is one of the many logging drivers which allows you to send messages to local or remote server by means of a network protocol. So lets get ourselves a syslog server …. running in a container of course ;):</p><pre>$ docker run -d -v /tmp:/var/log/syslog -p 127.0.0.1:5514:514/udp  --name rsyslog voxxit/rsyslog</pre><p>(<strong>NOTE</strong>: We’re using <a href="http://www.rsyslog.com/">rsyslog</a> which is an implementation of the syslog protocol)</p><p>and now lets launch our sample application but this time we will specify the logging driver to be used:</p><pre>$ docker run --log-driver=syslog --log-opt syslog-address=udp://127.0.0.1:5514 --log-opt syslog-facility=daemon --log-opt syslog-tag=app01 --name logging-02 -ti -d -v $(pwd):/tmp  -w /tmp python:2.7 python -u logging-01.py</pre><p>Let’s break down into pieces this last command line:</p><ul><li>syslog-tag=app01: A tag to apply to all messages coming from this container.</li><li>syslog-facility=daemon: The syslog facility to be used</li><li>— log-driver=syslog: We’re explicitly configuring our container to use the syslog driver.</li><li>— log-opt syslog-address=udp://127.0.0.1:5514: This indicates which syslog server we want to ship messages to and whether it should be done using TCP or UDP.</li></ul><p>(<em>NOTE</em>: If you need a crash course on syslog you can check the <a href="https://en.wikipedia.org/wiki/Syslog">Wikipedia entry</a> or <a href="https://blog.logentries.com/2014/08/what-is-syslog/">this link</a>)</p><p>It’s time to check if log messages are making it to their final destination. If you’re like me, you will go and type:</p><pre>$ docker logs -f logging-02<br>&quot;logs&quot; command is supported only for &quot;json-file&quot; logging driver (got: syslog)</pre><p>which will totally make sense once you give it a 5 seconds thought. There is no possible way, nor it should try to, the docker logs could work as we expected given that messages are sent to a potentially remote server. Instead we need to look into the rsyslog container which is acting as our syslog server:</p><pre>$ docker exec  rsyslog tail -f /var/log/messages<br>2015-09-16T01:05:17Z default docker/app01[989]: Error<br>2015-09-16T01:05:17Z default docker/app01[989]: All Good</pre><p>see how our app01 tag is present on each message? Now let’s launch a new instance of our sample application but this time we will use a new tag:</p><pre>$ docker run --log-driver=syslog --log-opt syslog-address=udp://127.0.0.1:5514 --log-opt syslog-facility=daemon --log-opt syslog-tag=app02 --name logging-03 -ti -d -v $(pwd):/tmp  -w /tmp python:2.7 python -u logging-01.py<br>$ docker exec  rsyslog tail -f /var/log/messages<br>2015-09-16T01:11:27Z default docker/app02[989]: Error<br>2015-09-16T01:11:27Z default docker/app02[989]: All Good<br>2015-09-16T01:11:28Z default docker/app01[989]: Error<br>2015-09-16T01:11:28Z default docker/app01[989]: All Good</pre><p>and now we have messages coming from the new container tagged app02.</p><h2>What’s next?</h2><p>The syslog driver is an enhancement over the json-file one, specially for environments with multiple applications powered by containers, at the cost of introducing a dependency on a external service. It is also a step forward towards centralization of logging messages. However as the number of applications grow, and so it does the number of running containers, your will find your self in need of a tool letting you search for specific log messages based on a date/time range, a keyword, etc ((don’t grep-me on this one please ;)).</p><p>In the next article of these series we will take a look at the gelf and fluentd driver to see how they might help to overcome some of the issues mentioned above.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b23ef1443aac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>