Updated on 2024-06-19 GMT+08:00

Migrating Images to SWR Using image-syncer

Scenarios

If 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, decompress, and run image-syncer.

    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 preceding commands, swr.××××.myhuaweicloud.com indicates the image repository address. You can obtain the username and password from the login command as follows:

    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

    For security, the example username and password are not complete. You should use the actual username and password obtained from the console.

  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.

    --namespace

    default-namespace. default-namespace can also be set by environment variable DEFAULT_NAMESPACE. If they are both set at the same time, DEFAULT_NAMESPACE will not work at this synchronization. default-namespace will work only if default-registry is not empty.

    --proc

    Number of goroutines. The default value is 5.

    --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 they are both set at the same time, DEFAULT_REGISTRY will not work at this synchronization. default-registry will work only if default-namespace is not empty.

    After the migration command is executed, you can log in to the target image repository to view the migrated images.