{"id":359708,"date":"2021-10-29T14:56:28","date_gmt":"2021-10-29T11:56:28","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/where-does-docker-keep-log-files-cloudsavvy-it\/"},"modified":"2021-10-29T14:56:28","modified_gmt":"2021-10-29T11:56:28","slug":"where-does-docker-keep-log-files-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/where-does-docker-keep-log-files-cloudsavvy-it\/","title":{"rendered":"#Where Does Docker Keep Log Files? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2fcc02d5367\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2fcc02d5367\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/where-does-docker-keep-log-files-cloudsavvy-it\/#Where_Are_Logs_Stored\" >Where Are Logs Stored?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/where-does-docker-keep-log-files-cloudsavvy-it\/#Viewing_Logs_From_Apps_Inside_Containers\" >Viewing Logs From Apps Inside Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/where-does-docker-keep-log-files-cloudsavvy-it\/#Viewing_Docker_Daemon_Logs\" >Viewing Docker Daemon Logs<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Where Does Docker Keep Log Files? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-14169\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1200\" height=\"675\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Debugging most Linux programs usually involves checking log files, which can be a complex process. When running in a containerized environment under Docker though, you\u2019ll need to use more specific tools to debug <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>s in production.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Where_Are_Logs_Stored\"><\/span>Where Are Logs Stored?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The simple answer is that Docker stores container logs in its main storage location, <code>\/var\/lib\/docker\/<\/code>. Each container has a log specific to their ID (the full ID, not the shortened one that\u2019s usually displayed) and you can access it like so:<\/p>\n<pre>\/var\/lib\/docker\/containers\/ID\/ID-json.log<\/pre>\n<p>That\u2019s\u00a0<em>where<\/em> they\u2019re stored, but since they\u2019re in a JSON format, they\u2019re not easily readable, and having to use the full container ID is annoying. Docker provides a built in command for viewing them:<\/p>\n<pre>docker logs -f e4bd48ef3103<\/pre>\n<p>Here, the <code>-f<\/code>\u00a0flag will keep the prompt open and \u201cfollow\u201d any new entries in the file. You can also <code>--tail<\/code>\u00a0the file, or use <code>--timestamps<\/code>\u00a0to display the log time, or use <code>--until<\/code> and\u00a0<code>--since<\/code>\u00a0to filter based on time.<\/p>\n<p>If you\u2019re using Docker Compose, you can use the log command from that to view all logs easily:<\/p>\n<pre>docker-compose logs<\/pre>\n<p>However, one thing you\u2019ll notice is that this is STDOUT and STDERR, which is useful for lots of things, but only shows you the console output of the entrypoint specified by \u201cCMD\u201d in the Docker file. Many apps have their own dedicated logging systems, which often log to files like <code>\/var\/log\/nginx\/access.log<\/code>. Accessing logs like this is still possible from the host side through Docker.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Viewing_Logs_From_Apps_Inside_Containers\"><\/span>Viewing Logs From Apps Inside Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Depending on the container, this might not be necessary. For example, the default NGINX container is set up to send its Docker logs to STDOUT to make log checking easier. It does this with a symlink from <code>\/dev\/stdout<\/code>\u00a0to the log file, and you can set up something similar for your containers.<\/p>\n<pre>RUN ln -sf \/dev\/stdout \/var\/log\/nginx\/access.log &#13;\n&amp;&amp; ln -sf \/dev\/stderr \/var\/log\/nginx\/error.log<\/pre>\n<p>But, if you want to check out specific files inside a container, you can do so. Docker provides the <code>exec -it<\/code>\u00a0command to allow you to run any command inside any running Docker process. Using this, you can tail a log file inside a Docker container:<\/p>\n<pre>docker exec -it e4bd48ef3103 tail -f log.txt<\/pre>\n<p>Because this lets you run any command, you can use <code>journalctl <\/code> or any other debugging strategies you want, as long as you preface it with <code>docker exec -it<\/code>. You can even run <code>\/bin\/bash<\/code>\u00a0if you want to hop in and poke around.<\/p>\n<p>A more permanant solution that plays nicer with host services is to use a Docker volume mount. You can bind a directory like <code>\/var\/log\/nginx<\/code>\u00a0to a volume that\u2019s visible from the host. First, create a new volume:<\/p>\n<pre>docker volume create nginx-logs<\/pre>\n<p>And run the container with the <code>--mount<\/code>:<\/p>\n<pre>docker run -d &#13;\n--name devtest &#13;\n--mount source=nginx-logs,target=\/var\/log\/nginx &#13;\nnginx:latest<\/pre>\n<p>If you\u2019re using Docker Compose, the process can be automated:<\/p>\n<pre>version:\u00a0\"3.0\"&#13;\nservices:&#13;\n  web:&#13;\n    image: nginx:latest&#13;\n    ports:&#13;\n      -\u00a0\"80:80\"&#13;\n    volumes:&#13;\n      - nginx-logs:\/var\/log\/nginx\/&#13;\nvolumes:&#13;\n  nginx-logs:<\/pre>\n<p>This way, log files will be directly ingestable by any log aggregation services on the host machine.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Viewing_Docker_Daemon_Logs\"><\/span>Viewing Docker Daemon Logs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you instead want to view logs specific to the overall Docker service on your server, and not any specific containerized app, you\u2019ll want to view the <code>journalctl<\/code>\u00a0logs:<\/p>\n<pre>sudo journalctl -fu docker.service<\/pre>\n<p>This is where it\u2019s stored on most systems, but it\u2019s in a different spot on some:<\/p>\n<ul>\n<li>Amazon Linux: <code>\/var\/log\/docker<\/code><\/li>\n<li>CentOS\/RHEL: <code>\/var\/log\/messages | grep docker<\/code><\/li>\n<li>macOS: <code>~\/Library\/Containers\/com.docker.docker\/Data\/log\/vm\/dockerd.log<\/code><\/li>\n<li>Windows: <code>AppDataRoamingDockerlogvmdockerd.log<\/code><\/li>\n<\/ul>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14533\/where-does-docker-keep-log-files\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Where Does Docker Keep Log Files? \u2013 CloudSavvy IT&#8221; Debugging most Linux programs usually involves checking log files, which can be a complex process. When running in a containerized environment under Docker though, you\u2019ll need to use more specific tools to debug apps in production. Where Are Logs Stored? The simple answer is that Docker&#8230;<\/p>\n","protected":false},"author":1,"featured_media":359709,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-359708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/359708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=359708"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/359708\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/359709"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=359708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=359708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=359708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}