Gitlab/How To/Create a GitLab Container-Registry Read Token and Configure DOCKER_AUTH_CONFIG for private runner image
How To Create a GitLab Container-Registry Read Token and Configure DOCKER_AUTH_CONFIG for Private Runner Image
Overview
- This guide shows you how to create a GitLab Project Access Token with read_registry scope, securely capture it, build and export a DOCKER_AUTH_CONFIG JSON blob, and configure your GitLab CI/CD pipeline to use private Docker images with a custom runner.
- For DevOps engineers or project maintainers who need to pull private images in GitLab CI/CD jobs using the Docker executor.
Prerequisites
Steps
- 1. Create a Project Access Token
- 2. Securely Read the Token in Zsh
- 3. Build and Export DOCKER_AUTH_CONFIG
- 4. Store DOCKER_AUTH_CONFIG in GitLab CI/CD Settings
- 5. Reference in .gitlab-ci.yml
- GitLab Runner will automatically pick up
DOCKER_AUTH_CONFIGand use it when pulling images. In your.gitlab-ci.yml, you do NOT need to explicitly docker login—just ensure the variable is available:- yaml
image: name: registry.gitlab.com/your-group/your-private-image:latest # (optional) force fresh pull pull_policy: always variables: # If you're overriding, ensure DOCKER_AUTH_CONFIG is inherited DOCKER_AUTH_CONFIG: $DOCKER_AUTH_CONFIG stages: - build build-job: stage: build script: - echo "Building with private image..." # GitLab Runner uses DOCKER_AUTH_CONFIG to authenticate automatically - docker info
- Tip: You can verify that your runner is using the correct credentials by inspecting the job log for
Authenticating with credentials from DOCKER_AUTH_CONFIG
- GitLab Runner will automatically pick up
Troubleshooting
Related