Updated on 2024-10-14 GMT+08:00

Migrating Images to SWR Using image-syncer

Scenarios

If a small quantity of images need to be migrated, you can use Docker commands. However, for thousands of images and several TBs of image repository data, it takes a long time and even data may be lost. In this case, you can use the open source image migration tool image-syncer.

Procedure

  1. Download image-syncer. Then, decompress and run it.

    The following uses image-syncer v1.3.1 as an example.

    wget https://github.com/AliyunContainerService/image-syncer/releases/download/v1.3.1/image-syncer-v1.3.1-linux-amd64.tar.gz

    tar -zvxf image-syncer-v1.3.1-linux-amd64.tar.gz

  2. Create auth.json, the authentication information file of the image repositories.

    image-syncer can migrate Docker Registry V2-based repositories. Write the authentication information of the source and target repositories. The following is an example:

    {
        "swr.××××.myhuaweicloud.com": {
            "username": "××××@F1I3Q……",
            "password": "2fd4c869ea0……"
        },
        "swr.××××.myhuaweicloud.com": {
            "username": "××××@4N3FA……",
            "password": "f1c82b57855f9d35……"
        }

    In the command, swr.××××.myhuaweicloud.com indicates the image repository address. You can obtain the username and password from the login command.

    Log in to the SWR console, and click Generate Login Command in the upper right corner to obtain the login command.

    Figure 1 Generating a login command

  3. Create images.json, the image synchronization description file.

    In the following example, the source repository address is on the left, and the target repository address is on the right. image-syncer also supports other description modes. For details, see README.md.
    {
    "swr.ap-southeast-3.myhuaweicloud.com/org-ss/canary-consumer": "swr.ap-southeast-1.myhuaweicloud.com/dev-container/canary-consumer"
     }

  4. Run the following command to migrate the images to SWR:

    ./image-syncer --auth=./auth.json --images=./images.json --namespace=dev-container --registry=swr.ap-southeast-1.myhuaweicloud.com --retries=3 --log=./log

    Table 1 Command parameter description

    Parameter

    Description

    --config

    Path of the configuration file. This file needs to be created before you start the synchronization. By default, the configuration file is the config.json file in the current directory. (This parameter can be replaced with parameters --auth and --images which represent authentication information and repository synchronization rules respectively.)

    --images

    Path of the image rules file. This file needs to be created before you start the synchronization. By default, the rule file is the images.json file in the current directory.

    --auth

    Path of the authentication file. This file needs to be created before you start the synchronization. By default, the authentication file is the auth.json file in the current directory.

    --log

    Path of the log file. Logs will be printed to Stderr by default. You need to use cat to check logs.

    --namespace

    default-namespace. default-namespace can also be set by environment variable DEFAULT_NAMESPACE. If both the parameter and environment variable are set, the parameter will take precedence. default-namespace will work only if default-registry is not empty.

    --proc

    Number of goroutines. The default value is 5. You are advised to use this value and do not change it.

    --retries

    Number of retries. The default value is 2. The retries of failed sync tasks will start after all sync tasks are executed once. Retrying sync tasks will resolve most occasional network problems during synchronization.

    --registry

    default-registry. default-registry can also be set by environment variable DEFAULT_REGISTRY. If both the parameter and environment variable are set, the parameter will take precedence. default-registry will work only if default-namespace is not empty.

  5. Log in to the target image repository to check the migrated images.