How to use GitLab Container Registry

Content

Every GitLab project has its own container registry, and it is possible to upload many images there.

To enable Container Registry

container_register_enabled

Usually in new projects this feature is enabled by default, but in case it is not:

  1. Go to Settings -> General
  2. Expand the Visibility, project features, permissions & enable Container Registry
  3. Save changes
  4. Go to Packages > Container Registry to check that is has been enabled.

To login in the registry

In order to push to the registry of a project, you need to connect to it with the following Docker command:

docker login registry.git.rwth-aachen.de

GitLab username & password are needed.

To build an image

To build a new image from scratch you just need to specify its tag in the scheme that follows:

docker build -t registry.git.rwth-aachen.de/<group>/<project>(/image:version) .

Needs to be inside the folder where the Dockerfile is.

The < image > as well as the < version > fields are optional and can be omitted.

To tag an already existing image

To use an image that already exists, you just have to tag it with an appropriate name:

docker tag <NAME_OF_ALREADY_EXISTING_IMAGE> registry.git.rwth-aachen.de/<group>/<project>(/image:version)

The < image > can be the same as <NAME_OF_ALREADY_EXISTING_IMAGE>.

The < image > as well as the < version > fields can be omitted.

To push an image to the registry

Finally, to push the image to the project’s container registry:

docker push registry.git.rwth-aachen.de/<group>/<project>/<image>

Examples

Building a new image from a Dockerfile and pushing it to the GitLab Registry

  1. step

    docker login registry.git.rwth-aachen.de
    

    Note: Only the first time you will be asked for a username and password (used in GitLab instance).

  2. step

    docker build -t registry.git.rwth-aachen.de/ioannis.papagiannidis/ci-hello-world/my_image1 .
    

    docker_build

    docker_build_2

  3. step

    docker push registry.git.rwth-aachen.de/ioannis.papagiannidis/ci-hello-world/my_image1
    

    push_docker_image

    docker_image_pushed

Pushing an existing image to the GitLab Registry

  1. step

    docker login registry.git.rwth-aachen.de
    

    Only the first time you will be asked for a username and password (used in GitLab instance).

  2. step

    taged_existing_image

    sudo docker tag alpine registry.git.rwth-aachen.de/ioannis.papagiannidis/ci-hello-world/tagged_existing_image
    
  3. step

    push_taged_existing_image

    pushed_taged_existing_image

    sudo docker push registry.git.rwth-aachen.de/ioannis.papagiannidis/ci-hello-world/tagged_existing_i
    

See also