{"id":48357,"date":"2025-02-08T08:11:28","date_gmt":"2025-02-08T08:11:28","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=48357"},"modified":"2025-07-12T05:38:46","modified_gmt":"2025-07-12T05:38:46","slug":"docker-diff","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/docker-diff\/","title":{"rendered":"Docker commands Guide &#8211; docker diff with examples"},"content":{"rendered":"\n<p>Here\u2019s a <strong>complete tutorial<\/strong> on the <code>docker diff<\/code> command, explaining how it works, its purpose, and providing a comprehensive list of examples.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is <code>docker diff<\/code>?<\/strong><\/h2>\n\n\n\n<p><code>docker diff<\/code> is a Docker command used to <strong>inspect changes made to the filesystem<\/strong> of a container. It shows the differences between the <strong>container&#8217;s current state<\/strong> and its <strong>original image<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Key Features:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Lists changes to the <strong>container&#8217;s filesystem<\/strong>.<\/li>\n\n\n\n<li>Helps in <strong>debugging<\/strong> and <strong>auditing<\/strong> what files have been added, modified, or deleted in the container.<\/li>\n\n\n\n<li>Useful for verifying the impact of commands executed inside a running container.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Basic Syntax<\/strong><\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">docker<\/span> <span class=\"hljs-selector-tag\">diff<\/span> <span class=\"hljs-selector-attr\">&#91;OPTIONS]<\/span> <span class=\"hljs-selector-tag\">CONTAINER<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><strong>Options:<\/strong><\/h3>\n\n\n\n<p>There are no specific options for <code>docker diff<\/code>. You simply provide the <strong>container name or ID<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Output Explanation<\/strong><\/h2>\n\n\n\n<p><code>docker diff<\/code> provides three types of changes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>A<\/strong> \u2192 File or directory was <strong>added<\/strong> to the container.<\/li>\n\n\n\n<li><strong>C<\/strong> \u2192 File or directory was <strong>changed<\/strong> (modified).<\/li>\n\n\n\n<li><strong>D<\/strong> \u2192 File or directory was <strong>deleted<\/strong> from the container.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example Output:<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">C \/etc\/hostname\nA \/new_file.txt\nD \/tmp\/old_log.txt\n<\/code><\/span><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>C \/etc\/hostname<\/code> \u2192 <code>\/etc\/hostname<\/code> was modified.<\/li>\n\n\n\n<li><code>A \/new_file.txt<\/code> \u2192 <code>new_file.txt<\/code> was added to the container.<\/li>\n\n\n\n<li><code>D \/tmp\/old_log.txt<\/code> \u2192 <code>old_log.txt<\/code> was deleted from <code>\/tmp<\/code>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Examples of <code>docker diff<\/code><\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Check Changes in a Running Container<\/strong><\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker diff my_container\n<\/code><\/span><\/pre>\n\n\n<p>This command shows all changes to the <code>my_container<\/code> filesystem.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Check Changes After Modifying a File<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Start a container: <code>docker run -dit --name my_ubuntu ubuntu<\/code><\/li>\n\n\n\n<li>Modify or create a file in the container: <code>docker exec my_ubuntu bash -c \"echo 'Hello Docker' > \/tmp\/hello.txt\"<\/code><\/li>\n\n\n\n<li>Run <code>docker diff<\/code> to check the change: <code>docker diff my_ubuntu<\/code> <strong>Output:<\/strong> <code>A \/tmp\/hello.txt<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Detect Deleted Files<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Start a container: <code>docker run -dit --name my_nginx nginx<\/code><\/li>\n\n\n\n<li>Delete a file inside the container: <code>docker exec my_nginx rm \/etc\/nginx\/conf.d\/default.conf<\/code><\/li>\n\n\n\n<li>Run <code>docker diff<\/code>: <code>docker diff my_nginx<\/code> <strong>Output:<\/strong> <code>D \/etc\/nginx\/conf.d\/default.conf<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Monitor Changes in a Container&#8217;s Temporary Files<\/strong><\/h3>\n\n\n\n<p>Containers often generate temporary files in <code>\/tmp<\/code> or <code>\/var<\/code> during operation. You can use <code>docker diff<\/code> to track these changes:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker diff my_temp_container\n<\/code><\/span><\/pre>\n\n\n<p>This helps identify logs or cache files added during runtime.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Check Changes in a Stopped Container<\/strong><\/h3>\n\n\n\n<p>You can run <code>docker diff<\/code> on both running and stopped containers:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker diff stopped_container\n<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Debugging File Changes in a Database Container<\/strong><\/h3>\n\n\n\n<p>If you&#8217;re running a MySQL container and suspect that files in <code>\/var\/lib\/mysql<\/code> have been modified:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker diff my_mysql\n<\/code><\/span><\/pre>\n\n\n<p>This will list all changes in the <code>\/var\/lib\/mysql<\/code> directory, helping you verify data persistence or accidental modifications.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Combine <code>docker diff<\/code> with Other Commands<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Using <code>docker diff<\/code> with <code>docker exec<\/code><\/strong><\/h4>\n\n\n\n<p>To confirm a change detected by <code>docker diff<\/code>, use <code>docker exec<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker exec my_container cat \/path\/to\/file\n<\/code><\/span><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Using <code>docker diff<\/code> with <code>docker commit<\/code><\/strong><\/h4>\n\n\n\n<p>If you want to save a modified container after detecting changes:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">docker commit my_container my_new_image\n<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>List of Common <code>docker diff<\/code> Commands<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Command<\/strong><\/th><th><strong>Description<\/strong><\/th><\/tr><\/thead><tbody><tr><td><code>docker diff my_container<\/code><\/td><td>Show all changes in the container\u2019s filesystem<\/td><\/tr><tr><td><code>docker diff stopped_container<\/code><\/td><td>Inspect changes in a stopped container<\/td><\/tr><tr><td><code>docker diff my_nginx<\/code><\/td><td>Check changes in an NGINX container<\/td><\/tr><tr><td><code>docker diff my_database<\/code><\/td><td>Monitor changes in a database container<\/td><\/tr><tr><td><code>docker diff container_id<\/code><\/td><td>Use container ID to check for filesystem changes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Best Practices for <code>docker diff<\/code>:<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Use <code>docker diff<\/code> for debugging<\/strong> unexpected behavior in containers.<\/li>\n\n\n\n<li><strong>Combine with <code>docker commit<\/code><\/strong> to create a new image from a modified container.<\/li>\n\n\n\n<li><strong>Regularly monitor changes<\/strong> in critical containers (e.g., databases, web servers).<\/li>\n\n\n\n<li><strong>Avoid leaving unnecessary files<\/strong> in containers\u2014<code>docker diff<\/code> helps track them.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Errors and Solutions<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>&#8220;Error response from daemon: No such container&#8221;<\/strong><br>\u2192 Ensure the container name or ID is correct and the container exists.<\/li>\n\n\n\n<li><strong>&#8220;No changes detected&#8221;<\/strong><br>\u2192 This means no changes have been made since the container was created.<\/li>\n\n\n\n<li><strong>Permission Denied Errors<\/strong><br>\u2192 Ensure you have the necessary permissions to inspect the container.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a complete tutorial on the docker diff command, explaining how it works, its purpose, and providing a comprehensive list of examples. What is docker diff? docker diff is a&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862],"tags":[],"class_list":["post-48357","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=48357"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48357\/revisions"}],"predecessor-version":[{"id":48359,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48357\/revisions\/48359"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=48357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=48357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=48357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}