<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Docker on Marouane LAARIF scribbles</title>
    <link>https://blog.laarif-marouane.com/tags/docker/</link>
    <description>Recent content in Docker on Marouane LAARIF scribbles</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>marouane.laarif94@gmail.com (LAARIF Marouane)</managingEditor>
    <webMaster>marouane.laarif94@gmail.com (LAARIF Marouane)</webMaster>
    <lastBuildDate>Sun, 13 Jul 2025 13:01:11 +0100</lastBuildDate>
    <atom:link href="https://blog.laarif-marouane.com/tags/docker/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Understanding and Fixing Docker Socket Permissions</title>
      <link>https://blog.laarif-marouane.com/posts/fix-docker-socket-permission/</link>
      <pubDate>Sun, 13 Jul 2025 13:01:11 +0100</pubDate><author>marouane.laarif94@gmail.com (LAARIF Marouane)</author>
      <guid>https://blog.laarif-marouane.com/posts/fix-docker-socket-permission/</guid>
      <description>&lt;p&gt;You&amp;rsquo;re installing Ubuntu server, you get a screen where you can pick &amp;ldquo;snaps&amp;rdquo; to install, and like many, you probably opted for the convenient &amp;ldquo;Docker&amp;rdquo; checkbox during installation, expecting a smooth, out-of-the-box experience. However, to your surprise, when you tried to run your first Docker command, you were met with a frustrating &lt;strong&gt;&amp;ldquo;permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock&amp;rdquo;&lt;/strong&gt; error.&lt;/p&gt;&#xA;&lt;p&gt;This cryptic message, often followed by &lt;code&gt;Get &amp;quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.48/containers/json&amp;quot;: dial unix /var/run/docker.sock: connect: permission denied&lt;/code&gt;, indicates that your user doesn&amp;rsquo;t have the necessary permissions to communicate with the Docker daemon. This leaves you in a bind, unable to use Docker without &lt;code&gt;sudo&lt;/code&gt; for every command—which isn&amp;rsquo;t ideal for workflow or security.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>You&rsquo;re installing Ubuntu server, you get a screen where you can pick &ldquo;snaps&rdquo; to install, and like many, you probably opted for the convenient &ldquo;Docker&rdquo; checkbox during installation, expecting a smooth, out-of-the-box experience. However, to your surprise, when you tried to run your first Docker command, you were met with a frustrating <strong>&ldquo;permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock&rdquo;</strong> error.</p>
<p>This cryptic message, often followed by <code>Get &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.48/containers/json&quot;: dial unix /var/run/docker.sock: connect: permission denied</code>, indicates that your user doesn&rsquo;t have the necessary permissions to communicate with the Docker daemon. This leaves you in a bind, unable to use Docker without <code>sudo</code> for every command—which isn&rsquo;t ideal for workflow or security.</p>
<p>You try to add your user to the &ldquo;docker&rdquo; group so you can run docker without sudo. And surprise again, the &ldquo;docker&rdquo; group is not created.
You create the docker group, add your user to it, and still permission error.</p>
<p><strong>Why did this happen, especially with the Ubuntu installer&rsquo;s Docker checkbox?</strong></p>
<p>The Ubuntu server installer installs Docker as a <strong>Snap package</strong>. Snaps are designed for <strong>confinement and isolation</strong>, meaning they run in a more restricted environment for security. Unlike traditional <code>apt</code> package installations, the Docker Snap does not automatically handle the creation of the <code>docker</code> group or add your user to it due to this confinement model. This leaves you without direct access to the Docker socket, forcing you to use <code>sudo</code>.</p>
<h2 id="checking-and-correcting-docker-socket-permissions">Checking and Correcting Docker Socket Permissions</h2>
<p>To check if the docker group is created run:</p>





<pre tabindex="0"><code>getent group | grep docker</code></pre><p>If the result is empty then create the group by running :</p>





<pre tabindex="0"><code>sudo groupadd docker</code></pre><p>and add your user:</p>





<pre tabindex="0"><code>sudo usermod -a -G docker {username}</code></pre><p>If your group membership is confirmed, let&rsquo;s look at the actual permissions of the Docker socket file:</p>





<pre tabindex="0"><code>ls -l /var/run/docker.sock</code></pre><p>You should typically see something like this:</p>





<pre tabindex="0"><code>srw-rw---- 1 root docker 0 Jul  X HH:MM /var/run/docker.sock</code></pre><p>Key things to look for:</p>
<ul>
<li><strong>Ownership:</strong> <code>root</code> should be the owner.</li>
<li><strong>Group:</strong> <code>docker</code> should be the group.</li>
<li><strong>Permissions:</strong> <code>srw-rw----</code> means:
<ul>
<li><code>s</code>: It&rsquo;s a socket file.</li>
<li><code>rw-</code>: Read and write for the owner (<code>root</code>).</li>
<li><code>rw-</code>: Read and write for the group (<code>docker</code>).</li>
<li><code>---</code>: No permissions for others.</li>
</ul>
</li>
</ul>
<p>If the group is <em>not</em> <code>docker</code> or the permissions are different (e.g., <code>rw-r-----</code>), it might be misconfigured.</p>
<p><strong>If the permissions are wrong, you can fix them:</strong></p>





<pre tabindex="0"><code>sudo chown root:docker /var/run/docker.sock
sudo chmod 660 /var/run/docker.sock</code></pre><p><strong>Important Note:</strong> Some guides suggest <code>sudo chmod 666 /var/run/docker.sock</code>. While this <em>will</em> fix the permission error, it&rsquo;s a <strong>security risk</strong> as it gives <em>everyone</em> read/write access to the Docker socket, which is equivalent to giving them root access to your system. <strong>Avoid <code>chmod 666</code> for the Docker socket.</strong></p>
]]></content:encoded>
    </item>
  </channel>
</rss>
