Building containers from inside a container
Hosted runners ship with Docker preinstalled. On self-hosted, especially when you containerize the runner itself, you need a strategy for running Docker commands inside the runner.
Three patterns
- Mount the host Docker socket —
/var/run/docker.sockinto the runner. Easiest. Insecure: a job can break out to the host. - Docker-in-Docker (dind) — run a separate Docker daemon inside the runner. Safer; slower; needs
--privilegedor rootless dind. - Buildkit standalone — for image builds only, Buildkit can run without dockerd. Slim and fast.
Recommendation
- For trusted code: socket mount is fine, easy, and fast.
- For untrusted code: rootless dind or Kaniko/Buildkit.
- For Apple Silicon: Docker Desktop on the Mac handles the daemon; runner agent talks to it normally.