dockerd will not start inside a Docker container
Could not mount /sys/kernel/security.Short answer
Running Docker inside a container needs two things: the container must be started with --privileged, and on cgroup v2 hosts the processes must be moved into a child cgroup before controllers are enabled. The official docker:dind image does both. A hand-made image that starts dockerd directly usually fails on one of them.
Fix it fast
1Find out which cause you have
Check whether the host uses cgroup v2 and whether the failing container is privileged.
ls /sys/fs/cgroup/cgroup.controllers # this file exists on cgroup v2 hosts docker inspect --format '{{.HostConfig.Privileged}}' my-dind2Match what you see, then jump to its fix
What does the error look like?
Could not mount /sys/kernel/security.Writing to cgroup.subtree_control fails with EBUSY (cgroup v2)
Cause 1 of 2
The container is not privileged
1Check
The Docker Hub page for the docker image states that --privileged is required for Docker-in-Docker to function properly. The dind helper script is written to run in a privileged container, and it reports Could not mount /sys/kernel/security when it cannot mount.
docker inspect --format '{{.HostConfig.Privileged}}' my-dind2Fix
Start the official dind image with --privileged. The flag is not a secure sandbox, so use it only on hosts you control and never expose the daemon without TLS.
docker run -d --name my-dind --privileged docker:dind3Verify
Run a command through the inner daemon.
docker exec my-dind docker run --rm hello-worldConfirmed by hub.docker.com
Cause 2 of 2
A custom image starts dockerd without the cgroup v2 setup
1Check
On cgroup v2 the root cgroup has processes in it, so enabling controllers for children fails with EBUSY. The dind script in the Moby repository creates an init child group, moves the processes into it, and then writes the controllers to cgroup.subtree_control. It only does this when /sys/fs/cgroup/cgroup.controllers exists.
docker exec my-dind ls /sys/fs/cgroup/cgroup.controllers2Fix
Use the official docker:dind image, or copy the dind script into your image and make it the wrapper around dockerd instead of starting dockerd on its own.
FROM docker:dind
# add your tools here, and keep the image's own entrypoint
RUN apk add --no-cache git3Verify
Start the container and confirm the inner daemon answers.
docker run -d --name my-dind --privileged my-dind-image
docker exec my-dind docker infoConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Prefer the official docker:dind image as the base for CI helpers.
- Keep TLS on for any daemon reachable over the network.
- Where possible, mount the host Docker socket for build jobs instead of nesting a daemon, accepting that the job then controls the host daemon.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A container started from inside a container sees an empty or missing mount
the files you mounted are not there in the second container
A bind mount is resolved by the Docker daemon, on the daemon's own host, not inside the container that typed the command.
3 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix