Setup GitLab Docker Registry

Startup

Run in a docker container, behind Traefik.

Add the following to the docker-compose YAML in setup.md.

    ...
        environment:
            GITLAB_OMNIBUS_CONFIG: |
                ...

                registry_external_url 'https://docker.example.com/'
                registry['enable'] = true
                registry_nginx['listen_port'] = 81
                registry_nginx['listen_https'] = false
                registry_nginx['real_ip_trusted_addresses'] = [ '172.0.0.0/8' ]
                registry_nginx['real_ip_header'] = 'X-Forwarded-For'
                registry_nginx['request_buffering_off_path_regex'] = '.?'

                ...

        ...

        labels:
            traefik.enable: 'true'

            traefik.gitlab.port: '80'
            traefik.gitlab.frontend.rule: 'Host: gitlab.example.com'

            traefik.registry.port: '81'
            traefik.registry.frontend.rule: 'Host: docker.example.com'

        ...

Important Notes

  • /var/opt/gitlab/gitlab-rails/shared/registry/docker
    • The docker images are stored here...
    • Their paths are not hashed like git repositories (which apparently means a project with docker images cannot be moved without deleting them first...)

Troubleshooting

Pushes Fail

If you see docker push failing with immediate "Retrying in 5 seconds" messages, and HTTP 500 responses in the logs, then make sure that the /var/opt/gitlab/gitlab-rails/shared/registry/docker directory is owned by UID 993, with permissions of at least 0755.