How do you build Docker images in GitLab CI without privileged mode?
AdvancedConceptGitLab CI
Answer
Docker-in-Docker (docker:dind service) needs a privileged runner, which gives the job near-root on the host. Rootless alternatives that need no daemon: Kaniko (archived by Google in 2025, forks exist), Buildah (buildah bud rootless), or BuildKit rootless. Another approach is mounting a remote BuildKit builder or using a dedicated, isolated build runner.
build:
image: quay.io/buildah/stable
script:
- buildah bud -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- buildah push --creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate