Getting Docker in Docker with Rootless to run

CJ Hewett
Sep 26, 2022

Iโ€™ve found that when trying to run the docker-in-docker image with rootless, I get the following error:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Turns out this is because the path to the Docker Host is actually unix:///run/user/1000/docker.sock and this was unfortunately left out of the documentation in the Docker docs (at the time of writing).

To get around this, you can use the following Dockerfile

FROM docker:20.10.10-dind-rootlessENV DOCKER_HOST=unix:///run/user/1000/docker.sock

and then this docker-compose.yml file:

version: '3.8'services:
dindtest:
build:
context: .
privileged: true

and then run docker-compose up and open another terminal and run docker exec -it [CONTAINER NAME] sh and you should be able to start running docker commands from within the container.

I hope you found this useful.
Chur ๐Ÿค™,

--

--

CJ Hewett

๐Ÿ›น Skateboarder. ๐Ÿ‚ Snowboarder. ๐Ÿ„ Websurfer. I write monthly* about Cloud/DevOps/IoT. AWS Certified DevOps Engineer and Terraform Associate