title: Why do I still getting error, Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock?
body: <p>I have installed docker inside my EC2 instance and running Jenkins as a docker container. The complete code is given below.</p>
  <pre><code>sudo su
  apt-get update 
  apt install -y docker.io 
  service docker start 
  usermod -a -G docker ubuntu
  chmod 666 /var/run/docker.sock 
  mkdir /data
  mkdir /data/jenkins
  chmod o+rwx /data
  chmod o+rwx /data/jenkins
  </code></pre>
  <p>Then to run the container,</p>
  <pre><code>docker run --name jenkins-dev -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:jdk11 
  </code></pre>
  <p>An then I entered inside the container by <code>docker exec -it 17cfbb0f966d</code> and install docker inside it as mentioned over <a href="https://faun.pub/how-to-install-docker-in-jenkins-container-4c49ba40b373" rel="nofollow noreferrer">here</a>. Then, the docker commands were working fine. But after re logging I can't run docker commands. It gives below error <code>Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json&quot;: dial unix /var/run/docker.sock: connect: permission denied</code>. I guess, after every login the permission for docker.sock file is changing. So i had to rerun <code>chmod 666 /var/run/docker.sock</code> in main terminal to work docker commands inside the container. But I tried another way to add user jenkins into docker group as well. It was successfully added to group &quot;docker&quot; as shown below.</p>
  <pre><code>ubuntu@ip-10-133-184-31:~$ docker exec -it 17cfbb0f966d bash
  jenkins@17cfbb0f966d:/$ grep /etc/group -e &quot;docker&quot;
  docker:x:999:jenkins
  </code></pre>
  <p>After that i rebooted the instance and started the container again. But still I can't run any docker commands inside the container. It throws the same error.</p>
  <pre><code>ubuntu@ip-10-133-184-31:~$ docker exec -it 17cfbb0f966d bash
  jenkins@17cfbb0f966d:/$ docker ps
  Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json&quot;: dial unix 
  /var/run/docker.sock: connect: permission denied
  </code></pre>
  <p>What may be the issue?</p>