Вы находитесь на странице: 1из 17

GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.

html

GitLab Container Registry administration


Version history

With the Container Registry integrated into GitLab, every project can have its own space to store its Docker images.
You can read more about the Docker Registry at https://docs.docker.com/registry/introduction/ .

Enable the Container Registry


Omnibus GitLab installations
If you are using the Omnibus GitLab built in Let’s Encrypt integration, as of GitLab 12.5, the Container Registry will be automatically
enabled on port 5050 of the default domain.
If you would like to use a separate domain, all you have to do is configure the domain name under which the Container Registry will
listen to. Read #container-registry-domain-configuration and pick one of the two options that fits your case.

Installations from source


If you have installed GitLab from source:

1. You will have to install Registry by yourself.


2. After the installation is complete, you will have to configure the Registry’s settings in gitlab.yml in order to enable it.
3. Use the sample NGINX configuration file that is found under lib/support/nginx/registry-ssl and edit it to match the host ,
port and TLS certs paths.

The contents of gitlab.yml are:

where:

Parameter Description

enabled true or false . Enables the Registry in GitLab. By default this is false .

host The host URL under which the Registry will run and the users will be able to use.

port The port under which the external Registry domain will listen on.

api_url The internal API URL under which the Registry is exposed to. It defaults to http://localhost:5000 .

key The private key location that is a pair of Registry’s rootcertbundle . Read the token auth configuration documentation .

1 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Parameter Description

This should be the same directory like specified in Registry’s rootdirectory . Read the storage configuration
path documentation . This path needs to be readable by the GitLab user, the web-server user and the Registry user. Read
more in #container-registry-storage-path.

issuer This should be the same value as configured in Registry’s issuer . Read the token auth configuration documentation .

At the absolute minimum, make sure your Registry configuration has container_registry as the service and
https://gitlab.example.com/jwt/auth as the realm:

Container Registry domain configuration


There are two ways you can configure the Registry’s external domain. Either:

Use the existing GitLab domain where in that case the Registry will have to listen on a port and reuse GitLab’s TLS certificate,
Use a completely separate domain with a new TLS certificate for that domain.

Since the container Registry requires a TLS certificate, in the end it all boils down to how easy or pricey it is to get a new one.
Please take this into consideration before configuring the Container Registry for the first time.

Configure Container Registry under an existing GitLab domain


If the Registry is configured to use the existing GitLab domain, you can expose the Registry on a port so that you can reuse the
existing GitLab TLS certificate.
Assuming that the GitLab domain is https://gitlab.example.com and the port the Registry is exposed to the outside world is 4567 ,
here is what you need to set in gitlab.rb or gitlab.yml if you are using Omnibus GitLab or installed GitLab from source
respectively.

Omnibus GitLab installations

1. Your /etc/gitlab/gitlab.rb should contain the Registry URL as well as the path to the existing TLS certificate and key used
by GitLab:

Note how the registry_external_url is listening on HTTPS under the existing GitLab URL, but on a different port.

If your TLS certificate is not in /etc/gitlab/ssl/gitlab.example.com.crt and key not in /etc/gitlab


/ssl/gitlab.example.com.key uncomment the lines below:

2 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

2. Save the file and reconfigure GitLab for the changes to take effect.
3. Validate using:

Installations from source

1. Open /home/git/gitlab/config/gitlab.yml , find the registry entry and configure it with the following settings:

2. Save the file and restart GitLab for the changes to take effect.
3. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).

Users should now be able to login to the Container Registry with their GitLab credentials using:

Configure Container Registry under its own domain


If the Registry is configured to use its own domain, you will need a TLS certificate for that specific domain (e.g.,
registry.example.com ) or maybe a wildcard certificate if hosted under a subdomain of your existing GitLab domain (e.g.,
registry.gitlab.example.com ).

Let’s assume that you want the container Registry to be accessible at https://registry.gitlab.example.com .

Omnibus GitLab installations

1. Place your TLS certificate and key in /etc/gitlab/ssl/registry.gitlab.example.com.crt and /etc/gitlab


/ssl/registry.gitlab.example.com.key and make sure they have correct permissions:

2. Once the TLS certificate is in place, edit /etc/gitlab/gitlab.rb with:

Note how the registry_external_url is listening on HTTPS.

3. Save the file and reconfigure GitLab for the changes to take effect.

If you have a wildcard certificate , you need to specify the path to the certificate in addition to the URL, in this case /etc/gitlab

3 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

/gitlab.rb will look like:

Installations from source

1. Open /home/git/gitlab/config/gitlab.yml , find the registry entry and configure it with the following settings:

2. Save the file and restart GitLab for the changes to take effect.
3. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).

Users should now be able to login to the Container Registry using their GitLab credentials:

Disable Container Registry site-wide

Omnibus GitLab

1. Open /etc/gitlab/gitlab.rb and set registry['enable'] to false :

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source

1. Open /home/git/gitlab/config/gitlab.yml , find the registry entry and set enabled to false :

2. Save the file and restart GitLab for the changes to take effect.

Disable Container Registry for new projects site-wide


If the Container Registry is enabled, then it will be available on all new projects. To disable this function and let the owners of a
project to enable the Container Registry by themselves, follow the steps below.
Omnibus GitLab installations

1. Edit /etc/gitlab/gitlab.rb and add the following line:

4 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source

1. Open /home/git/gitlab/config/gitlab.yml , find the default_projects_features entry and configure it so that


container_registry is set to false :

2. Save the file and restart GitLab for the changes to take effect.

Container Registry storage path

If you want to store your images on the filesystem, you can change the storage path for the Container Registry, follow the steps
below.
This path is accessible to:

The user running the Container Registry daemon.


The user running GitLab.

Omnibus GitLab installations


The default location where images are stored in Omnibus, is /var/opt/gitlab/gitlab-rails/shared/registry . To change it:

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source


The default location where images are stored in source installations, is /home/git/gitlab/shared/registry . To change it:

1. Open /home/git/gitlab/config/gitlab.yml , find the registry entry and change the path setting:

2. Save the file and restart GitLab for the changes to take effect.

Container Registry storage driver


You can configure the Container Registry to use a different storage backend by configuring a different storage driver. By default the
GitLab Container Registry is configured to use the filesystem driver, which makes use of storage path configuration.

5 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

The different supported drivers are:

Driver Description

filesystem Uses a path on the local filesystem

Azure Microsoft Azure Blob Storage

gcs Google Cloud Storage

s3 Amazon Simple Storage Service. Be sure to configure your storage bucket with the correct S3 Permission Scopes .

swift OpenStack Swift Object Storage

oss Aliyun OSS

Read more about the individual driver’s config options in the Docker Registry docs .

Omnibus GitLab installations


To configure the s3 storage driver in Omnibus:

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source


Configuring the storage driver is done in your registry config YML file created when you deployed your docker registry .
s3 storage driver example:

6 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Storage limitations
Currently, there is no storage limitation, which means a user can upload an infinite amount of Docker images with arbitrary sizes.
This setting will be configurable in future releases.

Change the registry’s internal port

The Registry server listens on localhost at port 5000 by default, which is the address for which the Registry server should accept
connections. In the examples below we set the Registry’s port to 5001 .

Omnibus GitLab

1. Open /etc/gitlab/gitlab.rb and set registry['registry_http_addr'] :

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source

1. Open the configuration file of your Registry server and edit the http:addr value:

2. Save the file and restart the Registry server.

Disable Container Registry per project


If Registry is enabled in your GitLab instance, but you don’t need it for your project, you can disable it from your project’s settings.
Read the user guide on how to achieve that.

Use an external container registry with GitLab as an auth endpoint


Omnibus GitLab
You can use GitLab as an auth endpoint with an external container registry.

1. Open /etc/gitlab/gitlab.rb and set necessary configurations:

7 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

2. A certificate-key pair is required for GitLab and the external container registry to communicate securely. You will need to create
a certificate-key pair, configuring the external container registry with the public certificate and configuring GitLab with the
private key. To do that, add the following to /etc/gitlab/gitlab.rb :

3. To change the container registry URL displayed in the GitLab Container Registry pages, set the following configurations:

4. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source

1. Open /home/git/gitlab/config/gitlab.yml , and edit the configuration settings under registry :

2. Save the file and restart GitLab for the changes to take effect.

Configure Container Registry notifications


You can configure the Container Registry to send webhook notifications in response to events happening within the registry.
Read more about the Container Registry notifications config options in the Docker Registry notifications documentation .

8 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Omnibus GitLab installations


To configure a notification endpoint in Omnibus:

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source


Configuring the notification endpoint is done in your registry config YML file created when you deployed your docker registry .
Example:

Container Registry garbage collection

Container Registry can use considerable amounts of disk space. To clear up some unused layers, the registry includes a garbage
collect command.
GitLab offers a set of APIs to manipulate the Container Registry and aid the process of removing unused tags. Currently, this is
exposed using the API, but in the future, these controls will be migrated to the GitLab interface.
Project maintainers can delete Container Registry tags in bulk periodically based on their own criteria, however, this alone does not
recycle data, it only unlinks tags from manifests and image blobs. To recycle the Container Registry data in the whole GitLab instance,
you can use the built-in command provided by gitlab-ctl .

Understanding the content-addressable layers


Consider the following example, where you first build the image:

9 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Now, you do overwrite :latest with a new version:

Now, the :latest tag points to manifest of sha256:222222 . However, due to the architecture of registry, this data is still accessible
when pulling the image my.registry.com/my.group/my.project@sha256:111111 , even though it is no longer directly accessible via the
:latest tag.

Recycling unused tags


There are a couple of considerations you need to note before running the built-in command:

The built-in command will stop the registry before it starts the garbage collection.
The garbage collect command takes some time to complete, depending on the amount of data that exists.
If you changed the location of registry configuration file, you will need to specify its path.
After the garbage collection is done, the registry should start up automatically.

If you did not change the default location of the configuration file, run:

This command will take some time to complete, depending on the amount of layers you have stored.
If you changed the location of the Container Registry config.yml :

You may also remove all unreferenced manifests, although this is a way more destructive operation, and you should first understand
the implications.

Removing unused layers not referenced by manifests

Introduced in Omnibus GitLab 11.10.

The GitLab Container Registry follows the same default workflow as Docker Distribution: retain all layers, even ones that are
unreferenced directly to allow all content to be accessed using context addressable identifiers.
However, in most workflows, you don’t care about old layers if they are not directly referenced by the registry tag. The registry-
garbage-collect command supports the -m switch to allow you to remove all unreferenced manifests and layers that are not
directly accessible via tag :

10 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Since this is a way more destructive operation, this behavior is disabled by default. You are likely expecting this way of operation, but
before doing that, ensure that you have backed up all registry data.

Performing garbage collection without downtime


You can perform a garbage collection without stopping the Container Registry by setting it into a read-only mode and by not using
the built-in command. During this time, you will be able to pull from the Container Registry, but you will not be able to push.

To enable the read-only mode:

1. In /etc/gitlab/gitlab.rb , specify the read-only mode:

2. Save and reconfigure GitLab:

This will set the Container Registry into the read only mode.
3. Next, trigger the garbage collect command:

This will start the garbage collection, which might take some time to complete.
4. Once done, in /etc/gitlab/gitlab.rb change it back to read-write mode:

5. Save and reconfigure GitLab:

11 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Running the garbage collection on schedule


Ideally, you want to run the garbage collection of the registry regularly on a weekly basis at a time when the registry is not being in-
use. The simplest way is to add a new crontab job that it will run periodically once a week.
Create a file under /etc/cron.d/registry-garbage-collect :

Troubleshooting
Before diving in to the following sections, here’s some basic troubleshooting:

1. Check to make sure that the system clock on your Docker client and GitLab server have been synchronized (e.g. via NTP).
2. If you are using an S3-backed Registry, double check that the IAM permissions and the S3 credentials (including region) are
correct. See the sample IAM policy for more details.
3. Check the Registry logs (e.g. /var/log/gitlab/registry/current ) and the GitLab production logs for errors (e.g. /var/log
/gitlab/gitlab-rails/production.log ). You may be able to find clues there.

Using self-signed certificates with Container Registry


If you’re using a self-signed certificate with your Container Registry, you might encounter issues during the CI jobs like the following:

The Docker daemon running the command expects a cert signed by a recognized CA, thus the error above.
While GitLab doesn’t support using self-signed certificates with Container Registry out of the box, it is possible to make it work by
instructing the docker-daemon to trust the self-signed certificates , mounting the docker-daemon and setting privileged =
false in the Runner’s config.toml . Setting privileged = true takes precedence over the docker-daemon:

Additional information about this: issue 18239.

unauthorized: authentication required when pushing large images

Example error:

12 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

GitLab has a default token expiration of 5 minutes for the registry. When pushing larger images, or images that take longer than 5
minutes to push, users may encounter this error.
Administrators can increase the token duration in Admin area > Settings > Container Registry > Authorization token duration
(minutes).

AWS S3 with the GitLab registry error when pushing large images
When using AWS S3 with the GitLab registry, an error may occur when pushing large images. Look in the Registry log for the
following error:

To resolve the error specify a chunksize value in the Registry configuration. Start with a value between 25000000 (25MB) and
50000000 (50MB).

For Omnibus installations

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

For installations from source

1. Edit config/gitlab.yml :

2. Save the file and restart GitLab for the changes to take effect.

Supporting older Docker clients


As of GitLab 11.9, we began shipping version 2.7.1 of the Docker container registry, which disables the schema1 manifest by default.
If you are still using older Docker clients (1.9 or older), you may experience an error pushing images. See omnibus-4145 for more
details.
You can add a configuration option for backwards compatibility.
For Omnibus installations

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

13 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

For installations from source

1. Edit the YML configuration file you created when you deployed the registry . Add the following snippet:

2. Restart the registry for the changes to take affect.

Docker connection error


A Docker connection error can occur when there are special characters in either the group, project or branch name. Special
characters can include:

Leading underscore
Trailing hyphen/dash
Double hyphen/dash

To get around this, you can change the group path, change the project path or change the branch name. Another option is to create
a push rule to prevent this at the instance level.

Image push errors


When getting errors or “retrying” loops in an attempt to push an image but docker login works fine, there is likely an issue with the
headers forwarded to the registry by NGINX. The default recommended NGINX configurations should handle this, but it might occur
in custom setups where the SSL is offloaded to a third party reverse proxy.
This problem was discussed in a docker project issue and a simple solution would be to enable relative URLs in the Registry.
For Omnibus installations

1. Edit /etc/gitlab/gitlab.rb :

2. Save the file and reconfigure GitLab for the changes to take effect.

For installations from source

1. Edit the YML configuration file you created when you deployed the registry . Add the following snippet:

2. Save the file and restart GitLab for the changes to take effect.

Enable the Registry debug server


The optional debug server can be enabled by setting the registry debug address in your gitlab.rb configuration.

After adding the setting, reconfigure GitLab to apply the change.


Use curl to request debug output from the debug server:

14 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

Advanced Troubleshooting

Sometimes it’s not obvious what is wrong, and you may need to dive deeper into the communication between the Docker client and
the Registry to find out what’s wrong. We will use a concrete example in the past to illustrate how to diagnose a problem with the S3
setup.

Unexpected 403 error during push


A user attempted to enable an S3-backed Registry. The docker login step went fine. However, when pushing an image, the output
showed:

This error is ambiguous, as it’s not clear whether the 403 is coming from the GitLab Rails application, the Docker Registry, or
something else. In this case, since we know that since the login succeeded, we probably need to look at the communication between
the client and the Registry.
The REST API between the Docker client and Registry is described here . Normally, one would just use Wireshark or tcpdump to
capture the traffic and see where things went wrong. However, since all communications between Docker clients and servers are
done over HTTPS, it’s a bit difficult to decrypt the traffic quickly even if you know the private key. What can we do instead?
One way would be to disable HTTPS by setting up an insecure Registry . This could introduce a security hole and is only
recommended for local testing. If you have a production system and can’t or don’t want to do this, there is another way: use
mitmproxy, which stands for Man-in-the-Middle Proxy.

mitmproxy
mitmproxy allows you to place a proxy between your client and server to inspect all traffic. One wrinkle is that your system needs
to trust the mitmproxy SSL certificates for this to work.
The following installation instructions assume you are running Ubuntu:

1. Install mitmproxy .
2. Run mitmproxy --port 9000 to generate its certificates. Enter CTRL - C to quit.

3. Install the certificate from ~/.mitmproxy to your system:

If successful, the output should indicate that a certificate was added:

15 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

To verify that the certificates are properly installed, run:

This will run mitmproxy on port 9000 . In another window, run:

If everything is set up correctly, you will see information on the mitmproxy window and no errors from the curl commands.

Running the Docker daemon with a proxy


For Docker to connect through a proxy, you must start the Docker daemon with the proper environment variables. The easiest way is
to shutdown Docker (e.g. sudo initctl stop docker ) and then run Docker by hand. As root, run:

This will launch the Docker daemon and proxy all connections through mitmproxy.

Running the Docker client


Now that we have mitmproxy and Docker running, we can attempt to login and push a container image. You may need to run as
root to do this. For example:

In the example above, we see the following trace on the mitmproxy window:

The above image shows:

The initial PUT requests went through fine with a 201 status code.

16 of 17 21-Feb-20, 4:55 PM
GitLab Container Registry administration | GitLab https://docs.gitlab.com/ee/administration/packages/container_registry.html

The 201 redirected the client to the S3 bucket.


The HEAD request to the AWS bucket reported a 403 Unauthorized.

What does this mean? This strongly suggests that the S3 user does not have the right permissions to perform a HEAD request .
The solution: check the IAM permissions again . Once the right permissions were set, the error will go away.

Help and feedback

DOCS FEEDBACK PRODUCT FEEDBACK GET HELP GET MORE FEATURES

If you spot an error or a need for improvement and would like to fix it yourself in a
merge request

If you would like to suggest an improvement to this doc

If you want to give quick and simple feedback on this doc

17 of 17 21-Feb-20, 4:55 PM

Вам также может понравиться