BigW Consortium Gitlab

container_registry.md 15.2 KB
Newer Older
1
# GitLab Container Registry administration
2

3
> [Introduced][ce-4040] in GitLab 8.8.
4

5 6
---

7 8 9 10 11
> **Notes:**
- Container Registry manifest `v1` support was added in GitLab 8.9 to support
  Docker versions earlier than 1.10.
- This document is about the admin guide. To learn how to use GitLab Container
  Registry [user documentation](../user/project/container_registry.md).
12

13 14
With the Container Registry integrated into GitLab, every project can have its
own space to store its Docker images.
15

16 17
You can read more about the Container Registry at
https://docs.docker.com/registry/introduction/.
18

19
## Enable the Container Registry
20

21
**Omnibus GitLab installations**
22

23
All you have to do is configure the domain name under which the Container
24 25
Registry will listen to. Read
[#container-registry-domain-configuration](#container-registry-domain-configuration)
26
and pick one of the two options that fits your case.
27 28

>**Note:**
29
The container registry works under HTTPS by default. Using HTTP is possible
30 31 32
but not recommended and out of the scope of this document.
Read the [insecure Registry documentation][docker-insecure] if you want to
implement this.
33

34 35
---

36 37
**Installations from source**

38 39
If you have installed GitLab from source:

40
1. You will have to [install Registry][registry-deploy] by yourself.
41
1. After the installation is complete, you will have to configure the Registry's
42
   settings in `gitlab.yml` in order to enable it.
43
1. Use the sample NGINX configuration file that is found under
44 45
   [`lib/support/nginx/registry-ssl`][registry-ssl] and edit it to match the
   `host`, `port` and TLS certs paths.
46 47 48 49 50 51 52 53 54

The contents of `gitlab.yml` are:

```
registry:
  enabled: true
  host: registry.gitlab.example.com
  port: 5005
  api_url: http://localhost:5000/
55
  key: config/registry.key
56 57 58 59 60 61 62 63
  path: shared/registry
  issuer: gitlab-issuer
```

where:

| Parameter | Description |
| --------- | ----------- |
64
| `enabled` | `true` or `false`. Enables the Registry in GitLab. By default this is `false`. |
65 66 67
| `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`. |
68
| `key`     | The private key location that is a pair of Registry's `rootcertbundle`. Read the [token auth configuration documentation][token-config]. |
69
| `path`    | This should be the same directory like specified in Registry's `rootdirectory`. Read the [storage configuration documentation][storage-config]. 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](#container-registry-storage-path). |
70 71
| `issuer`  | This should be the same value as configured in Registry's `issuer`. Read the [token auth configuration documentation][token-config]. |

72
>**Note:**
73 74 75
A Registry init file is not shipped with GitLab if you install it from source.
Hence, [restarting GitLab][restart gitlab] will not restart the Registry should
you modify its settings. Read the upstream documentation on how to achieve that.
76

77 78 79
At the absolute minimum, make sure your [Registry configuration][registry-auth]
has `container_registry` as the service and `https://gitlab.example.com/jwt/auth`
as the realm:
80 81 82 83 84 85 86 87 88 89

```
auth:
  token:
    realm: https://gitlab.example.com/jwt/auth
    service: container_registry
    issuer: gitlab-issuer
    rootcertbundle: /root/certs/certbundle
```

90
## Container Registry domain configuration
91

92 93 94 95 96 97 98 99 100
There are two ways you can configure the Registry's external domain.

- Either [use the existing GitLab domain][existing-domain] where in that case
  the Registry will have to listen on a port and reuse GitLab's TLS certificate,
- or [use a completely separate domain][new-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 is to get a new one.
101

102 103 104
Please take this into consideration before configuring the Container Registry
for the first time.

105
### Configure Container Registry under an existing GitLab domain
106

107 108 109
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.
110

111 112 113 114
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.
115

116 117 118
>**Note:**
Be careful to choose a port different than the one that Registry listens to (`5000` by default),
otherwise you will run into conflicts .
119

120 121 122 123
---

**Omnibus GitLab installations**

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

127 128
    ```ruby
    registry_external_url 'https://gitlab.example.com:4567'
129
    ```
130

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

134 135 136
    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:
137

138 139 140
    ```ruby
    registry_nginx['ssl_certificate'] = "/path/to/certificate.pem"
    registry_nginx['ssl_certificate_key'] = "/path/to/certificate.key"
141
    ```
142

143
1. Save the file and [reconfigure GitLab][] for the changes to take effect.
144

145 146
---

147
**Installations from source**
148

149 150 151 152 153 154 155 156 157
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `registry` entry and
   configure it with the following settings:

    ```
    registry:
      enabled: true
      host: gitlab.example.com
      port: 4567
    ```
158

159 160 161 162 163 164 165
1. Save the file and [restart GitLab][] for the changes to take effect.
1. 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:
166 167 168 169 170

```bash
docker login gitlab.example.com:4567
```

171
### Configure Container Registry under its own domain
172

173 174
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
175 176
a wildcard certificate if hosted under a subdomain  of your existing GitLab
domain (e.g., `registry.gitlab.example.com`).
177 178

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

181 182
---

183
**Omnibus GitLab installations**
184

185 186 187 188
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:
189

190 191 192 193 194 195 196 197 198
    ```bash
    chmod 600 /etc/gitlab/ssl/registry.gitlab.example.com.*
    ```

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

    ```ruby
    registry_external_url 'https://registry.gitlab.example.com'
    ```
199

200 201
    Note how the `registry_external_url` is listening on HTTPS.

202
1. Save the file and [reconfigure GitLab][] for the changes to take effect.
203

204 205 206 207 208
> **Note:**
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/gitlab.rb` will
look like:
>
209
```ruby
210 211
registry_nginx['ssl_certificate'] = "/etc/gitlab/ssl/certificate.pem"
registry_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/certificate.key"
212 213
```

214
---
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
**Installations from source**

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

    ```
    registry:
      enabled: true
      host: registry.gitlab.example.com
    ```

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

---
231

232 233
Users should now be able to login to the Container Registry using their GitLab
credentials:
234 235 236 237 238

```bash
docker login registry.gitlab.example.com
```

239
## Disable Container Registry site-wide
240

241 242 243 244 245
>**Note:**
Disabling the Registry in the Rails GitLab application as set by the following
steps, will not remove any existing Docker images. This is handled by the
Registry application itself.

246
**Omnibus GitLab**
247

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

250
    ```ruby
251
    registry['enable'] = false
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    ```

1. 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`:

    ```
    registry:
      enabled: false
    ```

1. Save the file and [restart GitLab][] for the changes to take effect.
269

270 271
## Disable Container Registry for new projects site-wide

272 273 274
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.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

---

**Omnibus GitLab installations**

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

    ```ruby
    gitlab_rails['gitlab_default_projects_features_container_registry'] = false
    ```

1. 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`:

    ```
    ## Default project features settings
    default_projects_features:
      issues: true
      merge_requests: true
      wiki: true
      snippets: false
      builds: true
      container_registry: false
    ```

1. Save the file and [restart GitLab][] for the changes to take effect.

308 309
## Container Registry storage path

310 311 312 313 314 315
>**Note:**
For configuring storage in the cloud instead of the filesystem, see the
[storage driver configuration](#container-registry-storage-driver).

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

317 318 319 320 321 322 323
This path is accessible to:

- the user running the Container Registry daemon,
- the user running GitLab

> **Warning** You should confirm that all GitLab, Registry and web server users
have access to this directory.
324 325

---
326

327
**Omnibus GitLab installations**
328

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

332
1. Edit `/etc/gitlab/gitlab.rb`:
333

334 335 336
    ```ruby
    gitlab_rails['registry_path'] = "/path/to/registry/storage"
    ```
337

338
1. Save the file and [reconfigure GitLab][] for the changes to take effect.
339

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
---

**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:

    ```
    registry:
      path: shared/registry
    ```

1. Save the file and [restart GitLab][] for the changes to take effect.
356

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
## 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](#container-registry-storage-path)
configuration.

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       |
| swift      | OpenStack Swift Object Storage      |
| oss        | Aliyun OSS                          |

Read more about the individual driver's config options in the
[Docker Registry docs][storage-config].

> **Warning** GitLab will not backup Docker images that are not stored on the
filesystem. Remember to enable backups with your object storage provider if
desired.

---

**Omnibus GitLab installations**

To configure the storage driver in Omnibus:

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

    ```ruby
    registry['storage'] = {
      's3' => {
        'accesskey' => 's3-access-key',
        'secretkey' => 's3-secret-key-for-access-key',
395 396
        'bucket' => 'your-s3-bucket',
        'region' => 'your-s3-region'
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
      }
    }
    ```

1. 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][registry-deploy].

Example:

```
storage:
  s3:
    accesskey: 'AKIAKIAKI'
    secretkey: 'secret123'
    bucket: 'gitlab-registry-bucket-AKIAKIAKI'
418
    region: 'your-s3-region'
419 420 421 422 423 424
  cache:
    blobdescriptor: inmemory
  delete:
    enabled: true
```

425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
## Change the registry's internal port

> **Note:**
This is not to be confused with the port that GitLab itself uses to expose
the Registry to the world.

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']`:

    ```ruby
    registry['registry_http_addr'] = "localhost:5001"
    ```

1. 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`][registry-http-config] value:

    ```
    http
      addr: localhost:5001
    ```

1. 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.

465
## Storage limitations
466

467 468 469
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.
470 471 472

## Changelog

473 474 475
**GitLab 8.8 ([source docs][8-8-docs])**

- GitLab Container Registry feature was introduced.
476

477 478 479
[reconfigure gitlab]: restart_gitlab.md#omnibus-gitlab-reconfigure
[restart gitlab]: restart_gitlab.md#installations-from-source
[wildcard certificate]: https://en.wikipedia.org/wiki/Wildcard_certificate
480
[ce-4040]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4040
481
[docker-insecure]: https://docs.docker.com/registry/insecure/
482 483
[registry-deploy]: https://docs.docker.com/registry/deploying/
[storage-config]: https://docs.docker.com/registry/configuration/#storage
484 485
[registry-http-config]: https://docs.docker.com/registry/configuration/#http
[registry-auth]: https://docs.docker.com/registry/configuration/#auth
486
[token-config]: https://docs.docker.com/registry/configuration/#token
487 488
[8-8-docs]: https://gitlab.com/gitlab-org/gitlab-ce/blob/8-8-stable/doc/administration/container_registry.md
[registry-ssl]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/support/nginx/registry-ssl
489 490
[existing-domain]: #configure-container-registry-under-an-existing-gitlab-domain
[new-domain]: #configure-container-registry-under-its-own-domain