How to run Docker inside a container running on Docker for Mac?

In Docker Toolbox for the Mac, there is a reasonable way to run Docker itself inside a Docker container. The use case is a CI workflow that produces Docker artifacts. There’s a pretty good discussion here:

In Docker on real Linux, it’s very easy, with just these volume mounts from the host to the CI container:

  docker run ... \
    -v $(which docker):/usr/bin/docker \
    -v /var/run/docker.sock:/var/run/docker.sock \

My question is, how to do the same with Docker for Mac? I’ve tried all variations I can think of of the Linux technique above. I can share the .sock between the host and the CI container, but not the Docker executable itself.

have u tried dind?

apt-get install, or whatever your distribution-specific equivalent is, inside your container; don’t try to bind-mount the executable. This should work:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:16.04 bash
apt-get install
docker version

(I’ve seen a couple of posts very recently on this exact topic that lead me to wonder whether Alpine binaries are actually compatible with other distributions; in this case because the Moby VM is Alpine and your other container probably isn’t, the other one where the container they were trying to run was Alpine. I know it’s a different libc.)

Got it! Many thanks for your speedy help.

I was running into the same issue. In fact that works with root user . However when using a different user e.g. jenkins (put into the docker group) it does not work any more. See