Skip to content

GitLab Container Registry

The GitLab Container Registry is a secure and private registry for Docker images. It allows you to build and push images from your CI/CD pipelines and pull images for deployment.

Log in to GitLab Registry with Docker

You need to be authenticated to be able to push images. It does not matter if the project is private or public.

docker login registry.gitlab.ice.ri.se
docker push registry.gitlab.ice.ri.se/group/project:latest

CI/CD integration

The following example demonstrates how to build and push a Docker image to the GitLab registry.

Create a project with a Dockefile and .gitlab-ci.yml.

Dockerfile
FROM alpine:latest
CMD echo "Hello, World!"

Copy and paste the following file into your project. It uses the kaniko-project to build the image using Kubernetes.

.gitlab-ci.yml
stages:
  - build

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:v1.14.0-debug
    entrypoint: [""]
  script:
    - /kaniko/executor
      --context "${CI_PROJECT_DIR}"
      --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
      --destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}"
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
      changes:
        - Dockerfile

This setup builds and pushes an image to the registry when a commit is made to Dockerfile in the default branch. The image is tagged with the commit tag, or latest if no tag is provided.

You can view the images in the project's registry by navigating to DeployContainer Registry.

Pull images

Pull images from the registry to deploy your application. The following example demonstrates how to pull an image from the registry:

docker pull registry.gitlab.ice.ri.se/group/project:latest
docker run registry.gitlab.ice.ri.se/group/project:latest
Hello, World!