<?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 Ying Kit Yuen on Medium]]></title>
        <description><![CDATA[Stories by Ying Kit Yuen on Medium]]></description>
        <link>https://medium.com/@ykyuen?source=rss-653f887c0d1c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*M7O7ZYAEejARsEu5.</url>
            <title>Stories by Ying Kit Yuen on Medium</title>
            <link>https://medium.com/@ykyuen?source=rss-653f887c0d1c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:36:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ykyuen/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[這是人們會說起的一年]]></title>
            <link>https://medium.com/@ykyuen/%E9%80%99%E6%98%AF%E4%BA%BA%E5%80%91%E6%9C%83%E8%AA%AA%E8%B5%B7%E7%9A%84%E4%B8%80%E5%B9%B4-bc6a95986fb8?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc6a95986fb8</guid>
            <category><![CDATA[香港]]></category>
            <category><![CDATA[反送中]]></category>
            <category><![CDATA[brecht]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 06:36:50 GMT</pubDate>
            <atom:updated>2020-06-15T06:37:38.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZDqleiEyZrB270fNdmrsw.jpeg" /><figcaption>這是人們會說起的一年。作者<a href="https://www.facebook.com/bununeveryday/">Umav</a></figcaption></figure><p>這是人們會說起的一年，<br>這是人們說起就沉默的一年。</p><p>老人看著年輕人死去。<br>傻瓜看著聰明人死去。</p><p>大地不再生產，它吞噬。<br>天空不下雨，只下鐵。</p><p><strong>布萊希特，1940</strong><br><strong>黃燦然譯</strong></p><p>Source: <a href="https://p-articles.com/critics/1126.html">自由與詩歌的流轉交換：王榆鈞</a></p><p>—</p><p>This is the year which people will talk about.<br>This is the year which people will be silent about.</p><p>The old see the young die.<br>The foolish see the wise die.</p><p>The earth no longer produces, it devours.<br>The sky hurls down no rain, only iron.</p><p><strong>Bertolt Brecht<br>Finnland 1940 (1940), trans. Sammy McLean in Poems, 1913–1956, p. 350 — Poems, 1913–1956 (1976)</strong></p><p>Source: <a href="https://libquotes.com/bertolt-brecht/quote/lbm7r2d">Lib Quotes</a></p><p>—</p><p>Das ist dieses Jahr, von dem man reden wird.<br>Das ist dieses Jahr, von dem man schweigen wird.</p><p>Die Alten sehen die Jungen Sterben.<br>Die Toerichten sehen die Weisen sterben.</p><p>Die Erde traegt nicht mehr, aber sie schluckt.<br>Der Himmel wirft keinen Regen, sondern nur Eisen.</p><p><strong>Berthold Brecht, 1940</strong></p><p>Source: <a href="https://books.google.com.hk/books?id=JyomfFKieTwC&amp;pg=PA350&amp;lpg=PA350#v=onepage&amp;q&amp;f=false">Google Book</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc6a95986fb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting the time interval of metrics collection in Boatswain]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@ykyuen/setting-the-time-interval-of-metrics-collection-in-boatswain-10c5f16f51f9?source=rss-653f887c0d1c------2"><img src="https://cdn-images-1.medium.com/max/1200/1*N0gR9gpnLLFlTOVyx9cOXA.jpeg" width="1200"></a></p><p class="medium-feed-snippet">Boatswain Agent 0.2.12 is released!</p><p class="medium-feed-link"><a href="https://medium.com/@ykyuen/setting-the-time-interval-of-metrics-collection-in-boatswain-10c5f16f51f9?source=rss-653f887c0d1c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ykyuen/setting-the-time-interval-of-metrics-collection-in-boatswain-10c5f16f51f9?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/10c5f16f51f9</guid>
            <category><![CDATA[boatswain]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Thu, 13 Feb 2020 14:22:45 GMT</pubDate>
            <atom:updated>2020-02-13T14:22:45.471Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Real time notification on Docker container status]]></title>
            <link>https://medium.com/@ykyuen/real-time-notification-on-docker-container-status-e11fe90becc0?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e11fe90becc0</guid>
            <category><![CDATA[boatswain]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 09:39:05 GMT</pubDate>
            <atom:updated>2020-01-21T09:39:05.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4k1liNXNKNwEo5oL9nnGw.jpeg" /></figure><p>In the recent release of the <a href="https://boatswain.io/">Boatswain</a> web portal (version 0.1.6), we have implemented a simple real time notification mechanism on the Docker container status. We hope this is helpful to engineer responding quickly to any unexpected issue happen on their container.</p><h3>Setup the real time notification</h3><p>Now, <a href="https://boatswain.io/">Boatswain</a> user could setup the real time notification on the <strong>Notification Settings</strong> page which in under the <strong>Settings</strong> menu on the top right hand corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*wadMzpSXSi34e1wEzIL4-g.jpeg" /><figcaption>Notification Settings</figcaption></figure><h4>Enable the real time notification</h4><p>Sometimes, not all the containers running on the <a href="https://www.docker.com/">Docker</a> server are our concerns. So we allow user to enable the notification feature selectively by using regular expression. Any containers with name matched with the regular expressions would have notification enabled.</p><p>Here are the two rules when setting up the regular expression:</p><ol><li>Include the / before and after.</li><li>Only accepts the i flag.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PUstitAEYvlMcW6kqPyObA.jpeg" /><figcaption>Configure the regular expression to enable notification</figcaption></figure><h4>Check out which container have notification enabled</h4><p>Below the regular expression form, there is a list showing the containers which have notification enabled. Any detected containers in the recent 24 hours will be listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0knbTZobWKHkwmR1c1yHw.jpeg" /><figcaption>List of notification enabled containers</figcaption></figure><p>Please note that the above list is just for reference and any newly added container would also have notification enabled as long as its name matched any regular expression.</p><h4>Receive the notification email</h4><p>Whenever the container status is changed, the email address associated with the corresponding <a href="https://boatswain.io/">Boatswain</a> account would receive an notification email. Here is an example:</p><pre>Hi ykyuen,</pre><pre>We have detected a status change of the following container:<br>---<br>Host:            camus<br>Container ID:    1d2ce3c96b372fc61622c0c0133efda6de24cd2fad2e8faab810b8539d3ce4a1<br>Container name:  nginx-test<br>Container image: nginx:latest<br>Command:         nginx -g &#39;daemon off;&#39;<br>Status change:   running -&gt; exited<br>Exit code:       0<br>Error:           <br>Is OOM killed:   No<br>---</pre><pre>- Boatswain Team<br> ____              _                     _<br>|  _ \            | |                   (_)<br>| |_) | ___   __ _| |_ _____      ____ _ _ _ __<br>|  _ &lt; / _ \ / _` | __/ __\ \ /\ / / _` | | &#39;_ \<br>| |_) | (_) | (_| | |_\__ \\ V  V / (_| | | | | |<br>|____/ \___/ \__,_|\__|___/ \_/\_/ \__,_|_|_| |_|</pre><h3>What’s next?</h3><p>We notice that <a href="https://boatswain.io/">Boatswain</a> consumes certain amount of server resources and user might hang back especially when his/her application is running on a small instance. So we are working on the Boatswain configuration and let user decide the frequency of the metrics and log collections.</p><p>Lastly, happy coding 👨‍💻 and wishing all the best to all of you 🎊 🐀 🎉.</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/real-time-notification-on-docker-container-status/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e11fe90becc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor Kubernetes cluster by running Boatswain as a DaemonSet]]></title>
            <link>https://medium.com/@ykyuen/monitor-kubernetes-cluster-by-running-boatswain-as-a-daemonset-97320de358d1?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/97320de358d1</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[boatswain]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 09:15:15 GMT</pubDate>
            <atom:updated>2020-01-09T09:15:15.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMXifK1PPMRDVsWHd3y1Gw.png" /></figure><p>In a <a href="https://kubernetes.io/">Kubernetes</a> cluster, each node has a container runtime for running containers in pods. <a href="https://kubernetes.io/">Kubernetes</a> supports various <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/">container runtimes</a> including:</p><ul><li><a href="https://www.docker.com/">Docker</a></li><li><a href="https://containerd.io/">containerd</a></li><li><a href="https://cri-o.io/">CRI-O</a></li></ul><p>So if the <a href="https://kubernetes.io/">Kubernetes</a> cluster is using <a href="https://www.docker.com/">Docker</a> as container runtime, we could install <a href="https://boatswain.io/">Boatswain</a> on the nodes and monitoring its status as well as collecting the container logs.</p><p><strong>NOTE: The example in this article is for experimental purpose and we do not suggest using </strong><a href="https://boatswain.io/"><strong>Boatswain</strong></a><strong> in any production </strong><a href="https://kubernetes.io/"><strong>Kubernetes</strong></a><strong> cluster.</strong></p><h3>The DaemonSet in Kubernetes</h3><p>In <a href="https://kubernetes.io/">Kubernetes</a>, we could deploy the <a href="https://boatswain.io/">Boatswain</a> pod as a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a>. Unlike a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Deployment</a> which we could replicates multiple pods across different nodes, a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a> makes sure that a single pod runs on the selected nodes even if the node is newly added to the cluster. It is particular useful for storage daemon, log collection and monitoring on the node.</p><h3>Running Boatswain as a DaemonSet</h3><p>Here are the steps about setting up the <a href="https://boatswain.io/">Boatswain</a> <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a> in a <a href="https://kubernetes.io/">Kubernetes</a> cluster.</p><ol><li>Create the Boatswain namespace</li><li>Setup the Boatswain token as a secret</li><li>Setup the config file of the Boatswain DaemonSet</li><li>Start the Boatswain DaemonSet</li></ol><h4>Create the Boatswain namespace</h4><p>Let’s create a new namespace to separate the <a href="https://boatswain.io/">Boatswain</a> setup from those already exist.</p><pre>kubectl create namespace boatswain</pre><h4>Setup the Boatswain token as a secret</h4><p>This token is required for running <a href="https://boatswain.io/">Boatswain</a>. We store it as a secret called <strong>boatswain</strong> and later use it in the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a> configuration.</p><pre>kubectl create secret generic boatswain --from-literal=token=&lt;TO_BE_REPLACED&gt; -n boatswain</pre><h4>Setup the config file of the Boatswain DaemonSet</h4><p>Here comes the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a> configuration.</p><p><strong>daemon-set.yaml</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/323f8c52b50264c3dc302c816340ba02/href">https://medium.com/media/323f8c52b50264c3dc302c816340ba02/href</a></iframe><p>Before saving the yaml file:</p><ol><li>Replace the version of <a href="https://boatswain.io/">Boatswain</a> at line 17.</li><li>Set the hostname of the target node which you want to install <a href="https://boatswain.io/">Boatswain</a> or remove line 37 and 38 for installation on all nodes.</li></ol><h4>Start the Boatswain DaemonSet</h4><p>Execute the following command to start the <a href="https://boatswain.io/">Boatswain</a> <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a>.</p><pre>kubectl create -f daemon-set.yaml</pre><p>Check the status of the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/">DaemonSet</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/005a6e5e14f735ece32c2ab23d151507/href">https://medium.com/media/005a6e5e14f735ece32c2ab23d151507/href</a></iframe><p>And we could read the metrics and logs on <a href="https://boatswain.io/">Boatswain</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qmG6i986BU_UzgIMgWm-oA.png" /><figcaption>Status of the Kubernetes node</figcaption></figure><h3>Summary</h3><p>The example above shows that it is possible to use <a href="https://boatswain.io/">Boatswain</a> to monitor the <a href="https://kubernetes.io/">Kuberenetes</a> cluster. But currently it might not able to show the network metrics (confirmed on GKE cluster above). It might be related to the security settings and so far we haven’t investigated further about this issue. Moreover, running <a href="https://boatswain.io/">Boatswain</a> on all nodes does not work well as the usage will hit the 2GB data limit of the beta trial in a few hours. If you have any suggestions or thoughts, please let us know. 😀</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/monitor-k8s-cluster-by-running-boatswain-as-a-daemonset/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97320de358d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor your Docker container status in real time]]></title>
            <link>https://medium.com/@ykyuen/monitor-your-docker-container-status-in-real-time-97fa67b15d42?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/97fa67b15d42</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[boatswain]]></category>
            <category><![CDATA[log-management]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Fri, 20 Dec 2019 09:17:14 GMT</pubDate>
            <atom:updated>2019-12-20T09:17:14.846Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPcwmvFmCIl4VLgJX1GFYw.png" /></figure><h3>The new Container Status dashboard!</h3><p>In the recent update of <a href="https://boatswain.io/">Boatswain</a> (agent version 0.2.11), it keeps track of all the container statuses, no matter running or stopped, and display them on the new <strong>Container Status</strong> dashboard implemented on the <a href="https://boatswain.io/">Boatswain.io</a>.</p><h4>The Container Status Timeline</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dm_I8-Dod-U_YDLh9hkMTw.png" /><figcaption>Container Status Timeline</figcaption></figure><p>With the timeline above, we could get a rough idea on the recent lifecycle of any container. There are all together 8 possible statuses:</p><ul><li>created</li><li>running</li><li>paused</li><li>restarting</li><li>exited</li><li>dead</li><li>removing</li><li>unknown</li></ul><p>Please note that <a href="https://boatswain.io/">Boatswain</a> makes his best effort to collect the container status and may not be able to acknowledge a change if a status duration is too short.</p><h4>The Container Info</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*boHNsDG3sAmZ06eD6A-DZg.png" /><figcaption>Container Info</figcaption></figure><p>This pane displays the current container status which is equivalent to the docker ps command.</p><h4>The Container Status History</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gRv2XZB8EF-Y9l-M-laDnw.png" /><figcaption>Container Status History</figcaption></figure><p>This table list out every change in status detected and it is just the textual format representing the timeline graph above. The first row with highlighted background is the current container status.</p><h4>Check out the latest status of all containers</h4><p>Other than the new <strong>Container Status</strong> dashboard, we also added a new pane in the <strong>Docker Status</strong> dashboard listing the current status of all the containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBDtZcOrLnMObmkfgtT-0Q.png" /><figcaption>List of all container status</figcaption></figure><h3>What’s next?</h3><p>We hope the above new feature could help <a href="https://www.docker.com/">Docker</a> users getting up-to-date information of their <a href="https://www.docker.com/">Docker</a> servers but dashboard is a just passive solution which means it is futile if you are not looking at it. <strong>Real time notification</strong> could fill this gap and that’s our final stage of development before the official launch. Stay tuned and follow us on <a href="https://twitter.com/BoatswainIO">twitter</a>!</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/monitor-your-docker-container-status-in-real-time/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97fa67b15d42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happened in Hong Kong on 11st August 2019]]></title>
            <link>https://medium.com/@ykyuen/what-happened-in-hong-kong-on-11st-august-2019-166a6e7a4247?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/166a6e7a4247</guid>
            <category><![CDATA[antielab]]></category>
            <category><![CDATA[police-misconduct]]></category>
            <category><![CDATA[hong-kong]]></category>
            <category><![CDATA[hong-kong-protests-2019]]></category>
            <category><![CDATA[police-brutality]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 03:53:45 GMT</pubDate>
            <atom:updated>2019-08-12T03:53:45.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KyWrxzPuBOHd2nvOYi6AYw.jpeg" /><figcaption>Police shooting directly to protestors at the escalator in a Tai Koo MTR station entrance.</figcaption></figure><h3>What is happening in Hong Kong?</h3><p>Since the beginning of June, large-scale, peaceful protests against the highly controversial extradition bill have been held weekly around Hong Kong. This extradition bill undermines Hong Kong’s autonomous status under “One Country, Two Systems”, and allows political refugees, foreigners, and locals alike to be extradited to China’s highly corrupt, unfair and unjust juridical system.</p><h3>So why are we protesting here?</h3><h4>Because of unprecedented acts of violence by the police demonstrated on 11st August 2019…</h4><ol><li>Police fire tear gas canisters indoor at Kwai Fong MTR station.</li><li>Police shot a girl in the eye, causing her permanently vision loss.</li><li>Police pretended to be protestors and planted evidence into the bags of arrested people.</li></ol><h3>What do the protestors wants?</h3><ol><li>Complete retraction of the extradition bill.</li><li>Independent investigation into police brutality.</li><li>Immediate implementation of true universal suffrage.</li><li>Declassification of the characterization “riot” for protests.</li><li>Amnesty for all detained/prosecuted protestors.</li></ol><h3>Pictures on 11st August 2019</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*iZzpgVDZRh8DXXqY3EVDcQ.jpeg" /><figcaption>A female protestor was head shot by police.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYcp0JBnrNW9HJr52_LoUw.jpeg" /><figcaption>The helmet of the above protestor has a label stating “Please don’t shoot the head of the protestors”.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdAyJ-qaf23-63xjnsbcLQ.png" /><figcaption>Police firing (tear gas/rubber bullet?) inside Kwai Fong MTR station.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*GpZwAhtB9vmHkIWxW5-IUA.jpeg" /><figcaption>Summary of Hong Kong Police brutality and misconduct on 11st August 2019.</figcaption></figure><h3>More resources about the protests in Hong Kong</h3><ul><li><a href="https://www.washingtonpost.com/world/2019/08/09/airport-sit-ins-citywide-strikes-street-protests-whats-happening-hong-kong/">The Washington Post — Airport sit-ins, citywide strikes and street protests: What’s happening in Hong Kong?</a></li><li><a href="https://www.youtube.com/watch?v=fDtM3dEJdHo">The New York Times Video — When a Mob Attacked Protesters in Hong Kong, the Police Walked Away | Visual Investigations</a></li><li><a href="https://www.youtube.com/watch?v=koTdqWz77AU">The New York Times Video — Hong Kong Protests: What Happened on July 1? | The Dispatch</a></li><li><a href="https://www.youtube.com/watch?v=gHfWuUhrKQg">The New York Times Video — Did Hong Kong Police Abuse Protesters? What the Videos Show. | Visual Investigations</a></li><li><a href="https://www.nytimes.com/2019/06/30/world/asia/did-hong-kong-police-abuse-protesters-what-videos-show.html">The New York Times — Did Hong Kong Police Abuse Protesters? What Videos Show</a></li><li><a href="https://www.youtube.com/watch?v=ebKrqHdJaak">Youtube video — #StandwithHK Guerrilla Projection: Hong Kong Protests</a></li></ul><h4>Credit to <a href="https://lihkg.com/">LIHKGers</a> for the content being used in this article.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=166a6e7a4247" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling HTTP request in Go Echo framework (2)]]></title>
            <link>https://medium.com/@ykyuen/handling-http-request-in-go-echo-framework-2-194b951b0ad5?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/194b951b0ad5</guid>
            <category><![CDATA[echo]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 09:41:07 GMT</pubDate>
            <atom:updated>2019-12-20T09:19:18.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1yFVfNBPOiYXh9qvI3kGhQ.png" /></figure><p>This is the second post about handling HTTP request in <a href="https://echo.labstack.com/">Echo</a> framework and we will continue to work on the example we made previously.</p><ul><li><a href="https://blog.boatswain.io/post/handling-http-request-in-go-echo-framework-1/">Handling HTTP request in Go Echo framework (1)</a></li></ul><p>This time we will create a simple HTML form and submit it as a POST request.</p><h3>Create a POST request endpoint</h3><p>Checkout this <a href="https://gitlab.com/ykyuen/handling-http-request-in-go-echo-example-1">repo</a> and create the <em>api/post_full_name.go</em> to handle the POST request. This new file is almost the same as <em>api/get_full_name.go</em> except the JSON is prettified before returning to the client.</p><p><strong>api/post_full_name.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6be0c55abf47f915a2c681073a9248b9/href">https://medium.com/media/6be0c55abf47f915a2c681073a9248b9/href</a></iframe><p>Add the new route in <em>main.go</em>.</p><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2029c3ff0b1ba5d886fdbf5ba73f571/href">https://medium.com/media/e2029c3ff0b1ba5d886fdbf5ba73f571/href</a></iframe><h4>Test the new endpoint using curl</h4><p>Run the <a href="https://echo.labstack.com/">Echo</a> server as send a POST request using <strong>curl</strong>.</p><pre>curl http://localhost:1323/api/post-full-name -H &quot;Content-Type: application/json&quot; -d &#39;{ &quot;first_name&quot;: &quot;Kit&quot;, &quot;last_name&quot;: &quot;Yuen&quot;  }&#39;</pre><p>Here is the example result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhL9YTq3YYTSz7bs_7ygtw.jpeg" /><figcaption>A JSON is return based on our POST request payload.</figcaption></figure><h3>Add an HTML form</h3><p>The POST request endpoint is ready and now we could add an HTML form and complete the whole setup. Let’s add the form in the about page.</p><p><strong>view/about.html</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e38b8cd4fbd699ae70cb3d3c7fd103e7/href">https://medium.com/media/e38b8cd4fbd699ae70cb3d3c7fd103e7/href</a></iframe><p>As the form submission required <strong>jQuery</strong>, let’s include it in the <em>view/base.html</em>.</p><p><strong>view/base.html</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b5e2be0148c05750e269108b90feaf5/href">https://medium.com/media/4b5e2be0148c05750e269108b90feaf5/href</a></iframe><h4>Test the HTML form in the about page</h4><p>Start the <a href="https://echo.labstack.com/">Echo</a> server and browse the about page. Fill in the first and last name and then click the submit button. It should show the response JSON as follow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_r3Ns3N0o7rPWkO-ZBAHSA.jpeg" /><figcaption>Click the submit button and get the response.</figcaption></figure><h4>The project structure</h4><p>Here is our new project structure. <em>(The project is renamed to </em><strong><em>handling-http-request-in-go-echo-example-2</em></strong><em>, make sure you set the </em><strong><em>import</em></strong><em> statement in the </em><a href="https://golang.org/"><em>Golang</em></a><em> source files correctly if you want to change the project name.)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/679e1bba285660895eef8a7f4c43ec30/href">https://medium.com/media/679e1bba285660895eef8a7f4c43ec30/href</a></iframe><h3>Summary</h3><p>This is the second episode of <a href="https://blog.boatswain.io/post/handling-http-request-in-go-echo-framework-1/">Handling HTTP request in Go Echo framework (1)</a> and we have added the following:</p><ul><li>Setup a POST request endpoint in the <a href="https://echo.labstack.com/">Echo</a> framework.</li><li>Prettify the JSON byte array.</li><li>Add an HTML form and bind it to the new POST request using AJAX in jQuery/javascript.</li></ul><p>The complete example could be found on <a href="https://gitlab.com/ykyuen/handling-http-request-in-go-echo-example-2">gitlab.com</a>.</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/handling-http-request-in-go-echo-framework-2/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=194b951b0ad5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling HTTP request in Go Echo framework (1)]]></title>
            <link>https://medium.com/@ykyuen/handling-http-request-in-go-echo-framework-1-2b564663024?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b564663024</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[echo]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 09:36:39 GMT</pubDate>
            <atom:updated>2019-04-21T07:29:24.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*vhPpQMPkO9pmGGriJQOObQ.png" /></figure><p>In the last post, we have discussed about how we could setup nested templates in <a href="https://echo.labstack.com/">Echo</a> framework.</p><ul><li><a href="https://blog.boatswain.io/post/setup-nested-html-template-in-go-echo-web-framework/">Setup nested HTML template in Go Echo web framework</a></li></ul><p>In the following sections, we will move on and see how we could make HTTP request in <a href="https://echo.labstack.com/">Echo</a> server and render the result back to the client. Let’s start with the <a href="https://gitlab.com/ykyuen/golang-echo-template-example">example</a> we did in the last article.</p><h3>Setup an API endpoint</h3><p>Firstly, create a new API endpoint and return a simple JSON which is later called by the <a href="https://echo.labstack.com/">Echo</a> server itself.</p><h4>Create new endpoint in the api folder</h4><p>Unlike a hardcoded JSON request, our new API endpoint takes the request input from JSON data, form data or query parameters as defined in the <em>model/example_request.go</em> and then return it the the client.</p><p><strong>model/example_request.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffba5b88babd5f1b375706df4fe4a818/href">https://medium.com/media/ffba5b88babd5f1b375706df4fe4a818/href</a></iframe><p><strong>api/get_full_name.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0f4428bf472c2e557b698332bb5d07f/href">https://medium.com/media/a0f4428bf472c2e557b698332bb5d07f/href</a></iframe><h4>Setup the route for the above API endpoint</h4><p>Add our new API endpoint route in <strong>main.go</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db0c8a370ace5801d7ee5f1d61a66a88/href">https://medium.com/media/db0c8a370ace5801d7ee5f1d61a66a88/href</a></iframe><h4>Test the new API endpoint</h4><p>Run the <a href="https://echo.labstack.com/">Echo</a> server as see if it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6J8YBGqhpp7wbHIfCyhrcQ.jpeg" /><figcaption>It works!</figcaption></figure><p>This new endpoint could serve the browser client directly or it could be called by the <a href="https://echo.labstack.com/">Echo</a> server itself.</p><h3>Call the API from Echo server</h3><h4>Create the response struct type</h4><p>Similar to the <em>model/example_request.go</em>, we need to define another struct type for the HTTP response.</p><p><strong>model/example_response.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/142edee9dc44dc1504bf313fffb206e4/href">https://medium.com/media/142edee9dc44dc1504bf313fffb206e4/href</a></iframe><h4>Show the new greeting message in the about page</h4><p>Let’s modify the about page handler such that it will show the greeting message.</p><p><strong>handler/about_handler.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b525f6bb0bda7be3700db8441ab9411/href">https://medium.com/media/4b525f6bb0bda7be3700db8441ab9411/href</a></iframe><h4>Test the about page</h4><p>Start the <a href="https://echo.labstack.com/">Echo</a> server and browse the about page. We could see the new greeting message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*WEBgvWrXtfpOOZ-YihHGkA.jpeg" /><figcaption>The greeting msg is now composed of the result of the API call.</figcaption></figure><h4>The project structure</h4><p>After making the above changes, the project structure should look like this. <em>(The project is renamed to </em><strong><em>handling-http-request-in-go-echo-example-1</em></strong><em>, make sure you set the </em><strong><em>import</em></strong><em> statement in the </em><a href="https://golang.org/"><em>Golang</em></a><em> source files correctly if you want to change the project name.)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72f42401c983def431534c6a465e3a0e/href">https://medium.com/media/72f42401c983def431534c6a465e3a0e/href</a></iframe><h3>Summary</h3><p>This article shows you how to setup a simple API endpoint in <a href="https://echo.labstack.com/">Echo</a> framework. Since <a href="https://golang.org/">Go</a> is a <strong>strongly typed</strong> language, we have to convert the JSON into well defined struct type before for we could manipulate its content. For example:</p><ul><li>Binding the GET request input to <strong>exampleRequest</strong> in <em>api/get_full_name.go</em>.</li><li>Unmarshal the GET response into <strong>exampleResponse</strong> in <em>handler/about_handler.go</em>.</li></ul><p>To invoke the API call, we could simply make use of the <a href="https://golang.org/">Go</a> standard <a href="https://golang.org/pkg/net/http/">net/http</a> library.</p><p>The complete example could be found on <a href="https://gitlab.com/ykyuen/handling-http-request-in-go-echo-example-1">gitlab.com</a>.</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/handling-http-request-in-go-echo-framework-1/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b564663024" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup a nested HTML template in the Go Echo web framework]]></title>
            <link>https://medium.com/free-code-camp/how-to-setup-a-nested-html-template-in-the-go-echo-web-framework-670f16244bb4?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/670f16244bb4</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[echo]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 23:01:58 GMT</pubDate>
            <atom:updated>2019-04-20T16:58:35.713Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*i1ZfgPCFQ95TeWWMiLa8wA.png" /></figure><p><a href="https://echo.labstack.com/">Echo</a> is a lightweight but complete web framework in <a href="https://golang.org/">Go</a> for building RESTful APIs. It is fast and includes a bunch of middleware for handling the whole HTTP request-response cycle. For the rendering part, it works with any template engine, but I use the standard <a href="https://godoc.org/html/template">html/template</a> package for the purpose of simplicity. By the end of this article, we will have a nested template <a href="https://echo.labstack.com/">Echo</a> project setup.</p><p>If you already have an idea on how <a href="https://echo.labstack.com/">Echo</a> works, jump to the <a href="#b8ff">Using a nested template section</a>.</p><h3>A basic Echo project setup</h3><h4>Create the project folder under the proper $GOPATH</h4><p>The complete project code is hosted on <a href="https://gitlab.com/ykyuen/golang-echo-template-example">GitLab</a>. First we’ll create the project folder here: <em>$GOPATH/src/gitlab.com/ykyuen/golang-echo-template-example</em>.</p><h4>Create the main.go</h4><p>Inside the newly created folder, let’s just copy the hello world example from the <a href="https://echo.labstack.com/">Echo</a> official site and create the <em>main.go</em>.</p><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5ba223c560e8ad392f06904249aed1c/href">https://medium.com/media/e5ba223c560e8ad392f06904249aed1c/href</a></iframe><h4>Download the Echo package using dep</h4><p>Simply run <strong>dep init</strong> if <a href="https://github.com/golang/dep">dep</a> is installed. You can refer to this post for more information about dep: <a href="https://blog.boatswain.io/post/manage-go-dependencies-using-dep/">Manage Go dependencies using dep</a>.</p><p>Or run <strong>go get github.com/labstack/echo</strong> to download the <a href="https://echo.labstack.com/">Echo</a> package in <em>$GOPATH</em>.</p><h4>Run the hello world</h4><p>Start the application by typing <strong>go run main.go </strong>and then visit <a href="http://localhost:1323/">http://localhost:1323</a> through the browser or the <strong>curl</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aExSnI6KPWva_VRT2-2wGg.jpeg" /><figcaption>Start the Echo server.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-u3NXp7_u7PTVUiYVGwFA.jpeg" /><figcaption>Send a request and get the hello world.</figcaption></figure><h3>Return a JSON response</h3><p>When building a RESTful API, it is more likely that the client wants to receive a JSON response instead of a string. Let’s write some <a href="https://golang.org/">Go</a> code in <em>main.go</em>.</p><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b64eca1f7d1f97d9108c975e30b4e464/href">https://medium.com/media/b64eca1f7d1f97d9108c975e30b4e464/href</a></iframe><h3>Return an HTML</h3><p>Similar to returning a JSON object, we just need to call another method in the <strong>return</strong> statement.</p><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31aa5b2e875a4e5a70bc28d593aaeef5/href">https://medium.com/media/31aa5b2e875a4e5a70bc28d593aaeef5/href</a></iframe><p>The above are just two simple examples. <a href="https://echo.labstack.com/">Echo</a> has a few more convenient ways to return JSON and HTML. For details please refer to the <a href="https://echo.labstack.com/guide/response">documentation</a>.</p><h4>Render HTML using template engine</h4><p>As mentioned at the very beginning, we could implement a template engine when returning the HTTP response. But before that, let’s restructure the project as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9451038941b0bf44e9a025b6612a9d4/href">https://medium.com/media/e9451038941b0bf44e9a025b6612a9d4/href</a></iframe><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/772f1e97d79c28188959e31480d7691c/href">https://medium.com/media/772f1e97d79c28188959e31480d7691c/href</a></iframe><p>In this <em>main.go</em>, we define a type called <strong>TemplateRegistry</strong> and implement the <a href="https://godoc.org/github.com/labstack/echo#Renderer"><strong>Renderer</strong></a> interface. A <strong>Renderer</strong> is a simple interface which wraps the <strong>Render()</strong> function. Inside a <strong>TemplateRegistry</strong> instance, it has a <strong>templates</strong> field containing all the templates needed for the <a href="https://echo.labstack.com/">Echo</a> server to render the html response and this is configured in the <strong>main()</strong> flow.</p><p>On the other hand, we define the <strong>HomeHandler</strong> in order to keep the logic in a separate file.</p><p><strong>handler/home_handler.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c57466637be60a843dde770435f6187/href">https://medium.com/media/5c57466637be60a843dde770435f6187/href</a></iframe><p>When the <strong>c.Render()</strong> is invoked, it executes the template which is already set in our <strong>TemplateRegistry</strong> instance as stated in <strong>main.go</strong>. The three parameters are:</p><ol><li>HTTP response code</li><li>The template name</li><li>The data object which could be used in the template</li></ol><p><strong>view/home.html</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/251fcd7175a986c55d26f9ed96b11824/href">https://medium.com/media/251fcd7175a986c55d26f9ed96b11824/href</a></iframe><p>This above template is named <strong>home.html</strong> as stated in the <strong>define</strong> statement. It can read the <strong>name</strong> and <strong>msg</strong> strings from <strong>c.Render()</strong> for the <strong>&lt;title&gt;</strong> and <strong>&lt;h1&gt;</strong> tags.</p><h4>Using nested template</h4><p>In the above setup, every HTML template has a complete set of HTML code and many of them are duplicated. Using nested template makes it easier to maintain the project.</p><p>Originally the <strong>templates</strong> field in the <strong>TemplateRegistry</strong> contains all the templates files. In the new setup, we make it into an <strong>map</strong> field and each item is a single set of template files for a particular HTML page.</p><p>We add a few files to the project and it should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9b6482bbe105f8da56c5709088be7f/href">https://medium.com/media/bf9b6482bbe105f8da56c5709088be7f/href</a></iframe><p>The code below is based on this <a href="https://gist.github.com/rand99/808e6e9702c00ce64803d94abff65678">gist</a> created by <a href="https://gist.github.com/rand99">rand99</a>.</p><p><strong>main.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30b7ff12cbd0ab8ed49f00b2fa099097/href">https://medium.com/media/30b7ff12cbd0ab8ed49f00b2fa099097/href</a></iframe><p>We add a new route <strong>/about</strong> which is handled by an <strong>AboutHandler.</strong> As you can see from the above lines <a href="https://gist.github.com/ykyuen/a8bcf35a338f398ddfe61275ac91e439#file-main-go-L34-L36">34-36</a>, the <strong>templates</strong> map contains different set of template files for different HTML pages. The <strong>Render()</strong> takes the <strong>name</strong> parameter as the <strong>templates</strong> map key so it can execute the correct template set.</p><p><strong>view/base.html</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10638896ee510d40bf2e8ff1fd4c7cae/href">https://medium.com/media/10638896ee510d40bf2e8ff1fd4c7cae/href</a></iframe><p>The <strong>template</strong> statement tells the template engine that it should look for the <strong>{{title}}</strong> and <strong>{{body}}</strong> definitions in the template set, and they are defined in the <strong>home.html</strong> as well as <strong>about.html</strong>.</p><p><strong>view/about.html</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5fb4fd871476421ae841875d1d4f016/href">https://medium.com/media/e5fb4fd871476421ae841875d1d4f016/href</a></iframe><p>And here is the <strong>AboutHanlder</strong> which has no big difference from the <strong>HomeHandler</strong>.</p><p><strong>handler/about_handler.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/528d91fd6a8b95422333e8339d0b7334/href">https://medium.com/media/528d91fd6a8b95422333e8339d0b7334/href</a></iframe><h3>Summary</h3><p>This is just a basic example implementing nested templates using the <a href="https://golang.org/">Go</a> standard <a href="https://godoc.org/html/template">html/template</a> library in <a href="https://echo.labstack.com/">Echo</a>. With proper setup, we could develop a more customized and convenient pattern for <a href="https://echo.labstack.com/">Echo</a> or even make it work with any other template engines.</p><p>The complete example can be found on <a href="https://gitlab.com/ykyuen/golang-echo-template-example">gitlab.com</a>.</p><p>— Originally posted on <a href="https://blog.boatswain.io/post/setup-nested-html-template-in-go-echo-web-framework/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=670f16244bb4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-setup-a-nested-html-template-in-the-go-echo-web-framework-670f16244bb4">How to setup a nested HTML template in the Go Echo web framework</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup log rotation for a Docker container]]></title>
            <link>https://medium.com/free-code-camp/how-to-setup-log-rotation-for-a-docker-container-a508093912b2?source=rss-653f887c0d1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a508093912b2</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ying Kit Yuen]]></dc:creator>
            <pubDate>Wed, 27 Jun 2018 22:50:15 GMT</pubDate>
            <atom:updated>2018-11-01T06:53:28.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_q2gpmanaKPIhoScKtgt1Q.png" /></figure><h4>We all need logs!</h4><p>Sometimes working with <a href="https://www.docker.com/">Docker</a> makes me feel like I’m working with a black box. Especially when I’m playing with Docker images from the community, and it doesn’t go the way I expected. In many cases, reading logs takes up a large portion of time when debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*PdclvVxyj07MQ_Fn8nJPYw.jpeg" /></figure><p>This article is about setting up log rotation for Docker containers.</p><h3>The default logging driver</h3><p>We can configure different logging drivers for containers. By default, the <strong>stdout</strong> and <strong>stderr</strong> of the container are written in a JSON file located in <em>/var/lib/docker/containers/[container-id]/[container-id]-json.log</em>. If you leave it unattended, it can take up a large amount of disk space, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2e9iGLyDCm5_WNfxl0_KAQ.jpeg" /><figcaption>A large log file in json format</figcaption></figure><h4>Purge the log manually</h4><p>If this JSON log file takes up a significant amount of the disk, we can purge it using the following command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ed0073461281c30f48ce4f43925c4d7/href">https://medium.com/media/4ed0073461281c30f48ce4f43925c4d7/href</a></iframe><p>We could setup a cronjob to purge these JSON log files regularly. But for the long term, it would be better to setup log rotation.</p><h3>Setup the log rotation</h3><h4>Configure the default logging driver</h4><p>This can be done by adding the following values in <em>/etc/docker/daemon.json</em>. Create this file if it doesn’t exist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81448754c57e06f35113761e645429fd/href">https://medium.com/media/81448754c57e06f35113761e645429fd/href</a></iframe><p>The <em>json-file</em> logging driver has a few more options, and we can even change to other logging drivers such as <em>syslog</em>. For more information, please refer to the <a href="https://docs.docker.com/config/containers/logging/configure/">Docker Docs — Configure logging drivers</a>.</p><p>Execute the following commands to reload the updated <em>daemon.json</em>. The new configuration will apply to all newly created containers after restart.</p><h4>Configure the logging driver for a container</h4><p>The configuration can also be done on the container level if you do not want to apply it globally.</p><p><strong>The docker run command</strong></p><p>We can specify the logging driver and options in the <em>docker run</em> command. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdc609eb93c842aa6a25acca4b58aa58/href">https://medium.com/media/cdc609eb93c842aa6a25acca4b58aa58/href</a></iframe><p><strong>Using docker-compose</strong></p><p>The logging driver and options can also be configured using docker-compose. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08a3cb3c93774e8445ba71401f2f98fd/href">https://medium.com/media/08a3cb3c93774e8445ba71401f2f98fd/href</a></iframe><p>Verify if the setup is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Pl6ERkWFB4HBZ9fVNvtsw.jpeg" /><figcaption>The logs are broken down into 1k files</figcaption></figure><h3>Summary</h3><p>Although the default settings work fine, you never know when the container logs take up all the disk space. This can be avoided by the few steps discussed above. Other than that, logs are an important asset. They are not only useful when something goes wrong, but they also contain a lot of hidden value. So never let the logs go.</p><p>If you are looking for a <strong>log management SAAS solution</strong>, consider using <a href="https://boatswain.io/">Boatswain</a>. We will help you manage all the logs and monitor your <a href="https://www.docker.com/">Docker</a> servers. 💫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*wU51pWBThLTG2ngSYcE7lA.jpeg" /><figcaption>Insufficient facts always invite danger</figcaption></figure><p>— Originally posted on <a href="https://blog.boatswain.io/post/docker-container-log-rotation/">Boatswain Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a508093912b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-setup-log-rotation-for-a-docker-container-a508093912b2">How to setup log rotation for a Docker container</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>