title: Permission denied error invoking Docker on Mac host from inside Docker Ubuntu container as non-root user
body: <p>I'm trying to invoke docker on my OSX host running Docker for Mac 17.06.0-ce-mac17 from inside a running jenkins docker container (<a href="https://hub.docker.com/_/jenkins/" rel="noreferrer">jenkins:latest</a>), per the procedure described at <a href="http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/" rel="noreferrer">http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/</a>.  </p>
  
  <p>I mount /var/run/docker.sock into the container, I stick a ubuntu docker binary inside it, and it's able to execute - but from inside the container as user "jenkins" when I run e.g. "docker ps" I get </p>
  
  <blockquote>
    <p>Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get <a href="http://%2Fvar%2Frun%2Fdocker.sock/v1.30/containers/json?all=1" rel="noreferrer">http://%2Fvar%2Frun%2Fdocker.sock/v1.30/containers/json?all=1</a>: dial unix /var/run/docker.sock: connect: permission denied.  </p>
  </blockquote>
  
  <p>If I connect to the container as root (docker exec -u 0) it works though.</p>
  
  <p>I need the jenkins user to be able to run this. I tried adding a docker group and adding jenkins to it inside the ubuntu container but that didn't help, since it's got nothing to do with the outside and Docker for Mac doesn't work like running this on linux where you can do semi easy uid/gid matching.  I want to distribute this container so answers that go and hack part of my Docker for Mac install won't really help me.  I'd rather not run the whole jenkins setup as root if I can help it.  (I also tried running the container as privileged, that didn't help.)</p>
  
  <p>Per the advice in <a href="https://stackoverflow.com/questions/44978017/permission-denied-while-trying-to-connect-to-docker-daemon-while-running-jenkins?rq=1">Permission Denied while trying to connect to Docker Daemon while running Jenkins pipeline in Macbook</a> I chowned the /var/run/docker.sock file inside the container manually to jenkins and now jenkins can run docker.  But I'm having trouble coming up with a solution for a distributable container - I can't do that chown in the Dockerfile because the file doesn't exist yet, and shimming in into the entrypoint doesn't help because that runs as jenkins.</p>
  
  <p>What do I need to do in order to build and run an image that will run external docker containers on my Mac as a non-root user from inside the container?</p>