{"id":839,"date":"2022-03-31T19:18:19","date_gmt":"2022-03-31T19:18:19","guid":{"rendered":"https:\/\/www.ebnet.us\/?p=839"},"modified":"2022-04-30T23:16:01","modified_gmt":"2022-05-01T03:16:01","slug":"how-to-rotate-the-traefik-access-log-in-docker-swarm","status":"publish","type":"post","link":"https:\/\/www.ebnet.us\/index.php\/2022\/03\/31\/how-to-rotate-the-traefik-access-log-in-docker-swarm\/","title":{"rendered":"How to rotate the Traefik access.log in Docker Swarm"},"content":{"rendered":"\n<p>I enabled <a href=\"https:\/\/traefik.io\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Traefik<\/strong><\/a> access logs to use in <strong><a href=\"https:\/\/grafana.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Grafana<\/a><\/strong> for a Traefik to <strong><a href=\"https:\/\/grafana.com\/oss\/loki\/\" target=\"_blank\" rel=\"noreferrer noopener\">Loki<\/a><\/strong> dashboard. I quickly found out Traefik access logs grow quickly and I would need to rotate the Traefik access.log in Docker Swarm. Since I have Traefik running in a container in Docker Swarm we will have to tell the logrotate daemon to find and a send a USR1 signal to the container. If we do not send a USR1 signal the container will stop logging when the log is rotated. While this post is focused on Traefik, the same principles should work for any container running as a Docker service writing logs to the host \/var\/log directory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"533\" src=\"https:\/\/ebnet.local.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard-1024x533.png\" alt=\"Traefik-Via-Loki-Dashboard\" class=\"wp-image-842\" srcset=\"https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard-1024x533.png 1024w, https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard-300x156.png 300w, https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard-768x400.png 768w, https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard-1536x800.png 1536w, https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Via-Loki-Dashboard.png 1803w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Grafana Traefik Via Loki Dashboard<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Logrotate Definition for Traefik access.log<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/var\/log\/traefik\/access.log {\n\tdaily\n\tcompress\n\tdelaycompress\n\tpostrotate\n\tdocker kill --signal=\"USR1\" $(docker ps | grep traefik | awk '{print $1}')\n\tendscript\n}<\/code><\/pre>\n\n\n\n<p>The important line is the post command <strong>&#8220;docker kill &#8211;signal=&#8221;USR1&#8243; $(docker ps | grep traefik | awk &#8216;{print $1}&#8217;)&#8221;<\/strong> which will find your container by its service name and send the needed USR1 signal<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I enabled Traefik access logs to use in Grafana for a Traefik to Loki dashboard. I quickly found out Traefik access logs grow quickly and I would need to rotate the Traefik access.log in Docker Swarm. Since I have Traefik running in a container in Docker Swarm we will have to tell the logrotate daemon&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":843,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[12,28,25,27],"tags":[9,10,26],"class_list":["post-839","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","category-linux","category-software","category-traefik","tag-docker","tag-dockerswarm","tag-traefik"],"featured_image_src":"https:\/\/www.ebnet.us\/wp-content\/uploads\/2022\/03\/Traefik-Logo.webp","author_info":{"display_name":"Ed Brandon","author_link":"https:\/\/www.ebnet.us\/index.php\/author\/bigeb\/"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/posts\/839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/comments?post=839"}],"version-history":[{"count":1,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/posts\/839\/revisions"}],"predecessor-version":[{"id":934,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/posts\/839\/revisions\/934"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/media\/843"}],"wp:attachment":[{"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/media?parent=839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/categories?post=839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ebnet.us\/index.php\/wp-json\/wp\/v2\/tags?post=839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}