Running a local docker registry

Why would you want to run a local registry?

  • If you are using vagrant to mimic your qa/staging/prod environments and want to make sure you run the same host OS
  • If you want to test multi-host deployments with Rancher, Kubernetes, Mesos or any other orchestration framework

Without a local registry every time a new docker host is provisioned all the images need to be pulled from the remote registry, this might not be a huge issue, but depending on how many services you run it could take some time to re-download all the images. By having a local registry caching all the images it makes sure you can provision ready to use environments very quickly.

To run the registry there are a few steps

Create configuration file

version: 0.1
  level: debug
  formatter: text
  secret: secret
  addr: :5000
    blobdescriptor: inmemory
    rootdirectory: /var/lib/registry

It is possible to override the settings of the config file via environment variables by using the SECTION_SECTION_... format, eg; STORAGE_CACHE_FILESYSTEM=/path However, it is recommended to drive the configuration of the registry via a file instead of environment variables. Settings worth mentioning:

  • storage_filesystem_rootdirectory - where to storage the image layers and repositories
  • proxy - enables a registry to be configured as a pull through cache

The official docs describe the configuration settings in more details.

Create compose file

version: '2'
    image: registry:2.4
      - "5000:5000"
      - "5001:5001"
      - /data/registry:/var/lib/registry
      serve /var/lib/registry/config.yml
          - registry.local

Bring the registry up

docker-compose up -d 

Verify the registry is online

curl -I localhost:5000 

List the repositories

curl localhost:5000/v2/_catalog 

It should come back as an empty array

    "repositories": []

Configure docker daemon to use the local registry

Where to change the configuration will depend on the distro you are using, but in any case, make sure the docker daemon is started with the following attributes:

Pull MySQL image

docker pull mysql:latest 

Verify the image has been cached

curl localhost:5000/v2/_catalog 

The MySQL repo should be present in the list

    "repositories": [

List the image tags

curl localhost:5000/v2/library/mysql/tags/list

Should list all the available tags for the image

    "name": "library/mysql",
    "tags": [