title: dial unix /var/run/docker.sock: connect: permission denied - Docker daemon socket - Jenkins on Ubuntu(ec2)
body: <p>I'm trying to build and then run a docker image on Jenkins. I have set up Jenkins on ubuntu on an AWS ec2 server. When I try to build I get this error:</p>
  <p><a href="https://i.stack.imgur.com/Lj60A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lj60A.png" alt="docker permission error on jenkins ubuntu ec2" /></a></p>
  <p>For reference, I have also attached my JenkinsFile.</p>
  <pre><code>pipeline {
      agent any
      stages {
          stage('Start') {
          steps {
              echo 'Starting to build the docker-react-app.'
          }
          }
          stage('building docker image') {
          steps {
              sh 'sudo docker build -t docker-react-app .'
          }
          }
          stage('runing docker image') {
          steps {
              sh 'sudo docker run -dp 3001:3000 docker-react-app'
          }
          }
      }
  }
  </code></pre>
  <p>I am using Jenkins with the default administrator account.</p>
  <p>I have also added the Jenkins user to the docker group. But it is hasn't solved the issue. I have also verified that by running:</p>
  <pre><code>cat /etc/group | grep docker
  </code></pre>
  <p>Which outputs:</p>
  <pre><code>docker:x:998:ubuntu,jenkins
  </code></pre>
  <p>Let me know if you need any further information.</p>