<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: cazgp</title>
    <description>The latest articles on Forem by cazgp (@cazgp).</description>
    <link>https://forem.com/cazgp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F52653%2F63d837c1-be1e-400d-98f1-6728cd03d833.png</url>
      <title>Forem: cazgp</title>
      <link>https://forem.com/cazgp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cazgp"/>
    <language>en</language>
    <item>
      <title>How To: GitLab and Docker Registry</title>
      <dc:creator>cazgp</dc:creator>
      <pubDate>Fri, 05 Jan 2018 15:51:59 +0000</pubDate>
      <link>https://forem.com/zaptic/how-to-gitlab-and-docker-registry-2moh</link>
      <guid>https://forem.com/zaptic/how-to-gitlab-and-docker-registry-2moh</guid>
      <description>&lt;h1&gt;
  
  
  How To: GitLab and Docker Registry
&lt;/h1&gt;

&lt;p&gt;I (and one other engineer) spent rather too much time the other afternoon trying to work out how to set up a self-hosted Docker registry on a self-hosted GitLab site.&lt;/p&gt;

&lt;p&gt;What we discovered (that the documentation really doesn't explain very well) is that GitLab becomes responsible for running the Docker registry and ensuring that it's accessible on whichever port you configure. That is, all you really need to do is to install Docker and change a couple of things in the GitLab config and everything happens like magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Set-Up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We assume that you have a self-hosted GitLab EE site somewhere, accessible by gitlab.example.com.&lt;/li&gt;
&lt;li&gt;We assume that this is on an Ubuntu (16.04) machine.&lt;/li&gt;
&lt;li&gt;We also assume that you want to set up a self-hosted Docker registry and that you know what that means.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Install Docker on your GitLab server
&lt;/h3&gt;

&lt;p&gt;Follow the instructions &lt;a href="https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/"&gt;here&lt;/a&gt; to install Docker.&lt;/p&gt;

&lt;p&gt;I'll copy out the commands to run to save you from the pain, but do check that link in case you don't know what any of these commands are doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get update

$ sudo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo apt-key fingerprint 0EBFCD88

$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) \
 stable"

$ sudo apt-get update

$ sudo apt-get install docker-ce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that docker installed properly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo docker run hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Make changes to GitLab config
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ce/administration/container_registry.html#enable-the-container-registry"&gt;The container docs&lt;/a&gt; say "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."&lt;/p&gt;

&lt;p&gt;Click on the link they provide and you reach &lt;a href="https://docs.gitlab.com/ce/administration/container_registry.html#container-registry-domain-configuration"&gt;here&lt;/a&gt; which says "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, or use a completely separate domain with a new TLS certificate for that domain."&lt;/p&gt;

&lt;p&gt;What we are trying to do is use the existing GitLab domain name because -- how cool is this? -- Docker registry login with GitLab credentials!&lt;/p&gt;

&lt;p&gt;So, click the link that takes us &lt;a href="https://docs.gitlab.com/ce/administration/container_registry.html#configure-container-registry-under-an-existing-gitlab-domain"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;... and it says "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."&lt;/p&gt;

&lt;p&gt;So, to summarise. The docs say "configure the domain name [for] the Container Registry ... If the Registry is configured [with] the existing [domain name]". But they completely fail to tell you how to configure the domain name! This is the part that confused us a lot.&lt;/p&gt;

&lt;h4&gt;
  
  
  The missing link
&lt;/h4&gt;

&lt;p&gt;We assume that you don't care what port you want to run Docker registry on, and so use 4567. If you do care, change that value.&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/gitlab/gitlab.rb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Find the line which contains &lt;code&gt;registry_external_url&lt;/code&gt; and change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;registry_external_url 'https://gitlab.example.com:4567'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable the registry in nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;registry_nginx['enable'] = true
registry_nginx['listen_port'] = 4567
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also copy in the TLS certificate lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;registry_nginx['ssl_certificate'] = "/path/to/certificate.pem"
registry_nginx['ssl_certificate_key'] = "/path/to/certificate.key"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and reconfigure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gitlab-ctl reconfigure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitLab will automatically open the ports up and allow you to login to the registry with &lt;code&gt;docker login&lt;/code&gt; and your GitLab credentials / 2fa keys (if you use 2fa).&lt;/p&gt;

&lt;p&gt;That should be it! Happy GitLabing :)&lt;/p&gt;

</description>
      <category>docker</category>
      <category>gitlab</category>
    </item>
  </channel>
</rss>
