title: Using docker into the jenkinsci/blueocean image
body: <h2>Context</h2>
  
  <p>I'm on Ubuntu and I want to run the official Jenkins image (i.e., <code>jenkinsci/blueocean</code>) into a docker container. I need also to allow the containerized Jenkins to access the Docker daemon on the host (i.e., Ubuntu). </p>
  
  <p>Using docker in docker has security <a href="http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/" rel="nofollow noreferrer">problems</a>. The alternative is just exposing the Docker socket to the container. Here is how I do it into my docker-compose:</p>
  
  <pre><code>volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
  </code></pre>
  
  <h2>Problem</h2>
  
  <p>The problem with this approach is that the <code>docker</code> GID among host and container is inconsistent. On the host side, the <code>docker</code> group is <code>999</code> but in the container it is <code>101</code> (<code>999</code> is the GID of the group <code>ping</code>, I guess this happens since this container is built on top of Alpine). Indeed:</p>
  
  <pre><code># This is the container shell, the group is ping
  bash-4.4$ ls -l /var/run/docker.sock
  srw-rw---- 1 root ping 0 Apr  8 16:20 /var/run/docker.sock
  </code></pre>
  
  <h2>Temporary fix (manual)</h2>
  
  <p>In order to fix I have just to open up a shell in the container as <code>root</code> and launch:</p>
  
  <pre><code>bash-4.4$ apk --no-cache add shadow
  bash-4.4$ usermod -aG docker jenkins
  </code></pre>
  
  <p>And I'm done.</p>
  
  <h2>What I need</h2>
  
  <p>I need a programmatic fix to have docker up &amp; running inside the official container when I spin it up. During the build phase, I cannot run <code>usermod -aG docker jenkins</code> since <code>/var/run/docker.sock</code> does not exist in the official image but it is bind-mounted later on at runtime.</p>
  
  <p>Is there a way to fix it programmatically the first time the container runs?</p>