Skip to main content

Log in with a Remote Docker Registry

You might need to authenticate your pipeline to a remote registry when running CI/CD pipelines in GitLab in order to access the necessary images. A GitLab pipeline can be authenticated to a remote registry using one of two methods:

1. CI/CD Using Environment Variables

Step 1: Add Environment Variables

Navigate to "Settings" in your GitLab project and choose "CI/CD" from the options. The necessary environment variables for authentication can be added by scrolling down to the "Variables" section. For instance, you can specify the following environment variables if you use Docker Hub:

DOCKER_USERNAME = your_docker_username
DOCKER_PASSWORD = your_docker_password

Step 2: Utilize Environment Variables in CI/CD

Use the environment variables in your `.gitlab-ci.yml` file to log in to the remote registry. For instance, you can use the code below to log in to Docker Hub:

before_script:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD

The environment variables specified in Step 1 will be used to authenticate to Docker Hub using this command.

2. Requesting the Cloud-Runner Team to Make the Change

The second method is to request a change to your runner from the Cloud-Runner team (support@cloud-runner.com) so that it includes the necessary credentials for the remote registry.

Note: This approach is not advised, as all jobs run by this runner will have access to the environment variable, posing a security risk. Only when the first image of your runner is stored on a private registry does it make sense to add the credential directly in the runner.

Using environment variables in your CI/CD pipeline or requesting the Cloud-Runner team to make the modification are the two ways to authenticate a GitLab pipeline to a remote registry.