Implementation ideas for docker registry image synchronization

Implementation ideas for docker registry image synchronization

Intro

Previously, our docker images were stored in Azure's Container Registry. Recently, we built our own docker registry. We want to synchronize the docker images previously saved in Azure's Container Registry to our own docker registry.

Implementation ideas

Our method is relatively simple and low-level, but it can basically meet the requirements.

Our approach is

  • First, get the list of all images in the source registry
  • Then get the image tags one by one
  • Then traverse and pull the corresponding images to the local computer, then docker tag them and name them as the new registry image name
  • Then push the docker image to the new registry
  • Delete the image downloaded to the local computer and the image pushed to the new registry

Later, I suddenly remembered that Alibaba Cloud seems to have an image synchronization tool, https://github.com/AliyunContainerService/image-syncer image-syncer is a docker image synchronization tool that can be used for many-to-many image repository synchronization. It supports most of the current mainstream docker image repository services. It is great to see the introduction. If you need to synchronize images between registries, you can try this tool. According to the introduction, this tool will not pull to the local disk. After getting the image data from the source registry, it will be directly pushed to the new registry, which will be much more efficient.

Docker-Registry API

Docker registry has a set of specifications, you can refer to https://docs.docker.com/registry/spec/api/ for more information

Get all images

Docker registry v2 adds a new _catalog API to get all images. v1 can be replaced by _search

The syntax is as follows:

GET /v2/_catalog

By default, a maximum of 100 records are returned. If the number of records is greater than 100, you can specify the number of records to return by using the parameter n . If you want to use paging, you can specify another parameter last to specify the last image to return after the previous page. For example: http://example.com/v2/_catalog?n=20&last=b

Get the image tag

To get the tag list of the docker image, you can use GET /v2/<repository-name>/tags/list to get it. You can also page it, similar to getting the image list above. You can use n and last to achieve paged loading.

Operation Example

A test docker registry is deployed locally for demonstration. I use httpie for testing.

Get the mirror list:

Call the _catalog interface to get the image list

http://5000/v2/_catalog

Get the tag list of the image

Call tags/list interface to obtain the image tag

http://5000/v2/busybox/tags/list
http:5000/v2/redis/tags/list

PowerShell script

Any operation and maintenance that is not automated is a hooligan. It is very likely that there will be similar needs in the future. It is better to write a script to run it automatically.

The following script is a bit simplified because there are not many images on our azure container registry, only about 50 or 60 images, and the image only has the latest tag, no other tags, so the above steps are simplified, and not all images are obtained by paging, nor all tags are obtained. If you actually use it, please modify it yourself before using it

# variables
$srcRegUser = "xxx"
$srcRegPwd = "111111"
$srcRegHost = "xxx.azurecr.cn"
$destRegUser = "yyy"
$destRegPwd = "222"
$destRegHost = "registry.xxx.com"

# get repositories from source registry
# httpie
$response = (http -b -a "${srcRegUser}:${srcRegPwd}" "https://${srcRegHost}/v2/_catalog") | ConvertFrom-Json
# curl
#$response = (curl -u "${srcRegUser}:${srcRegPwd}" "https://${srcRegHost}/v2/_catalog") | ConvertFrom-Json
# repository
$repositories = $response.repositories

#
Write-Host $repositories

# login source registry
docker login $srcRegHost -u $srcRegUser -p $srcRegPwd
# login dest registry
docker login $destRegHost -u $destRegUser -p $destRegPwd

# sync
foreach($repo in $repositories)
{
  Write-Host "sync $repo begin"

  $srcTag = "${srcRegHost}/${repo}:latest"
  $destTag = "${destRegHost}/${repo}:latest"

  Write-Host "source image tag: $srcTag"
  Write-Host "dest image tag $destTag"

  Write-Host "docker pull $srcTag begin"

  docker pull $srcTag

  Write-Host "docker pull $srcTag completed"

  Write-Host "docker tag $srcTag $destTag ing"

  docker tag $srcTag $destTag

  Write-Host "docker push $destTag begin"

  docker push $destTag

  Write-Host "docker push $destTag completed"
  
  Write-Host "docker rmi $srcTag $destTag begin"

  docker rmi $srcTag $destTag

  Write-Host "docker rmi $srcTag $destTag end"

  Write-Host "sync $repo completed"
}

Write-Host "Completed..."

More

If you need to synchronize many images, consider using Alibaba Cloud's image synchronization tool to synchronize them.

Reference

https://stackoverflow.com/questions/31251356/how-to-get-a-list-of-images-on-docker-registry-v2

https://github.com/AliyunContainerService/image-syncer

https://docs.docker.com/registry/spec/api/

Summarize

This is the end of this article about docker registry image synchronization. For more related docker registry image content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to implement Docker Registry to build a private image warehouse
  • How to query or obtain images in a private registry
  • Detailed explanation of Docker domestic image pulling and image acceleration registry-mirrors configuration modification
  • How to create a private repository using a Docker registry image
  • Detailed explanation of Docker Registry image deletion and garbage collection

<<:  Briefly understand the MYSQL database optimization stage

>>:  A complete guide to CSS style attributes css() and width() in jQuery

Recommend

How to configure Basic Auth login authentication in Nginx

Sometimes we build a file server through nginx, w...

Does the website's text still need to be designed?

Many people may ask, does the text on the website...

Things to note when writing self-closing XHTML tags

The img tag in XHTML should be written like this:...

Pure HTML+CSS to achieve typing effect

This article mainly introduces the typing effect ...

How to implement a single file component in JS

Table of contents Overview Single file components...

Detailed explanation of angular content projection

Table of contents Single content projection Multi...

WeChat applet scroll-view realizes left and right linkage

This article shares the specific code for WeChat ...

Pure JS method to export table to excel

html <div > <button type="button&qu...

Troubleshooting the reasons why MySQL deleted records do not take effect

A record of an online MySQL transaction problem L...

Docker custom network container interconnection

Table of contents Preface –link Custom Network As...

How to encapsulate axios in Vue

Table of contents 1. Installation 1. Introduction...

How to unify the character set on an existing mysql database

Preface In the database, some data tables and dat...

Notes on Using Textarea

Why mention textarea specifically? Because the tex...

Detailed explanation of MySQL InnoDB secondary index sorting example

Sorting Problem I recently read "45 Lectures...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...