A GitLab job needs to push a Docker image without Docker-in-Docker privileges.
IntermediateScenarioGitLab CI
Answer
Situation read → DinD needs privileged runners.
What I'd do →
- Use Kaniko or BuildKit rootless in the job image:
build_image:
image: { name: gcr.io/kaniko-project/executor:debug, entrypoint: [""] }
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile Dockerfile
--destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- Authenticate using
$CI_REGISTRY_USERand$CI_REGISTRY_PASSWORDwritten to/kaniko/.docker/config.json.
Why → No privileged container and no Docker socket on the runner.
Interview tip → Compare with docker:dind plus DOCKER_TLS_CERTDIR.
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