Module 7 Lesson 3: The GitLab Registry
·DevOps

Module 7 Lesson 3: The GitLab Registry

Everything in one place. Learn how to use GitLab's built-in container registry to store your images without needing external accounts or complicated login scripts.

Module 7 Lesson 3: The GitLab Registry

You don't need Docker Hub. Every GitLab project comes with its own Private Container Registry for free. It is significantly faster and more secure because the images never leave the GitLab network.

1. Zero-Config Login

GitLab automatically provides a temporary username and password for every job. You don't need to setup any variables!

build-job:
  image: docker:latest
  services: [docker:dind]
  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
    - docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .
    - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"

2. Viewing Your Images

  1. Go to Deploy -> Container Registry.
  2. You will see a list of every image you've pushed.
  3. You can delete old images manually or setup "Expiration Policies" to save space.

3. Why Use the GitLab Registry?

  1. Speed: Since the runner and the registry are in the same data center, pushing a 500MB image takes 10 seconds instead of 2 minutes.
  2. Permissions: If a person has "Developer" access to the code, they automatically have "Pull" access to the images. No need to manage extra passwords.
  3. Security Scanning: GitLab can automatically scan these images for vulnerabilities (Review Module 5).

4. The Image Path Anatomy

The path to your image looks like this: registry.gitlab.com/username/project-name:tag


Exercise: The All-in-One Repo

  1. Find the "Container Registry" link in your project's sidebar.
  2. Modify your existing build job to use the $CI_REGISTRY_IMAGE variable.
  3. Push your code.
  4. Once the pipeline finishes, refresh the Registry page in GitLab. Is your image there?
  5. Why is it better to use $CI_COMMIT_REF_SLUG (the branch name) as a tag rather than just "latest"?
  6. Research: How do you pull a private GitLab image onto your own laptop? (Hint: You need a "Personal Access Token").

Summary

The GitLab Registry is the ultimate "Shortcut" for DevOps. By keeping your images inside the same platform as your code and your pipelines, you eliminate 90% of the friction involved in managing external credentials and slow network speeds.

Next Lesson: Sky scale: Kubernetes integration with GitLab.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn