How to pull an image from a private registry
Sometimes, you need to access an image stored in a private registry, such as ghcr.io, which requires authentication.
- Log in to the registry
docker login ghcr.io -u <gh-username> -p <access-token> - Locate your Docker config file: the configuration is usually stored in
~/.docker/config.json. If it doesn’t exist, you can create it manually:{ "auths": { "ghcr.io": {}, } } - Add the
authattribute to the registry entry: The value must be a base64-encoded string of"username:password".{ "auths": { "ghcr.io": { "auth": "dXNlcm5hbWU6cGFzc3dvcmQ=" // value from `echo -n 'username:password' | base64` } } } - Encode the entire file in base64:
cat config.json | base64 - Create a Kubernetes Secret using the encoded config: Save the base64-encoded value in a Secret manifest:
apiVersion: v1 Kind: Secret type: kubernetes.io/dockerconfigjson metadata: name: ghcr-pull-secret namespace: formtion data: .dockerconfigjson: <base64-encoded-config-file> # set here your base64 encoded config.json - save the manifest
kubectl apply -f ghcr-pull-secret.yaml