I have a docker in docker setup for CI. Essentially, the machine has a jenkins CI server on it that uses the same machines docker socket to create nodes for CI.
Thi
You need to map the gid of the docker group on your host to the gid of a group that jenkins belongs to inside your container. Here's a sample from my Dockerfile of how I've built a jenkins slave image:
ARG DOCKER_GID=993
RUN groupadd -g ${DOCKER_GID} docker \
&& curl -sSL https://get.docker.com/ | sh \
&& apt-get -q autoremove \
&& apt-get -q clean -y \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*.bin
RUN useradd -m -d /home/jenkins -s /bin/sh jenkins \
&& usermod -aG docker jenkins
The 993 happens to be the gid of docker on the host in this example, you'd adjust that to match your environment.
Solution from the OP:
If rebuilding isn't a possibility you can set the docker group accordingly in using root and add the user. If you tried this before you may have to delete the group on the slave (groupdel docker):
docker exec -it -u root myjenkins bash
container $ groupadd -g 993 docker
container $ usermod -aG docker jenkins