title: How to mount docker socket as volume in docker container with correct group
body: <p>I want to run a Jenkins instance in a docker container.</p>
  
  <p>I want Jenkins itself to be able to spin up docker containers as slaves to run tests in.</p>
  
  <p>It seems the best way to do this is to use </p>
  
  <pre><code>docker run -v /var/run.docker.sock:/var/run/docker.sock -p 8080:8080 -ti my-jenkins-image
  </code></pre>
  
  <p><a href="http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/" rel="noreferrer">source</a></p>
  
  <p>The <code>Dockerfile</code> I'm using is </p>
  
  <pre><code>FROM jenkins
  COPY plugins.txt /usr/share/jenkins/plugins.txt
  RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
  
  USER root
  RUN apt-get update &amp;&amp; apt-get install -y docker.io
  RUN usermod -aG docker jenkins
  USER jenkins
  </code></pre>
  
  <p>If I start a bash session in my running container and run <code>docker info</code> on my image I get </p>
  
  <pre><code>$ docker info
  FATA[0000] Get http:///var/run/docker.sock/v1.18/info: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?
  </code></pre>
  
  <p>And if I run the bash session as root</p>
  
  <pre><code>docker exec -u 0 -ti cocky_mccarthy bash
  root@5dbd0efad2b0:/# docker info
  Containers: 42
  Images: 50
  ...
  </code></pre>
  
  <p>So I guess the <code>docker</code> group I'm adding the Jenkins user to is the group for the internal docker hence the socket is not readable without <code>sudo</code>. That's kind of a problem as the Jenkins docker plugin etc are not set up to use <code>sudo</code>.</p>
  
  <p><strong>How can I mount the socket so it can be used from the image without <code>sudo</code>?</strong></p>