如何使用 Google Cloud 从 Container Registry 部署 VM 映像

How can I deploy VM images from Container Registry using Google Cloud

我可以看到我的 VM 映像在执行命令后 Google Container Registry 中可用:

docker tag sutechnology/transcode eu.gcr.io/supereye/transcode

docker push eu.gcr.io/supereye/transcode

gcloud auth configure-docker docker push eu.gcr.io/supereye/transcode

虽然我可以看到图像,但在 Google Compute Engine 中创建新实例时无法使用此图像。在创建新的 VM 实例时,如何使用我在 Container Registry 中看到的图像?下面是我的完整配置:

machine_type = "zones/europe-west2-b/machineTypes/n1-standard-1"
disk_type = "zones/europe-west2-b/diskTypes/pd-standard"

config = {
    'name': name,
    'machineType': machine_type,

    # Specify the boot disk and the image to use as a source.
    'disks': [
        {
            'boot': True,
            'autoDelete': True,
            'initializeParams': {
                'sourceImage': source_disk_image,
            }
        }
    ],

    # Specify a network interface with NAT to access the public
    # internet.
    'networkInterfaces': [{
        'network': 'global/networks/default',
        'accessConfigs': [
            {'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
        ]
    }],

    # Allow the instance to access cloud storage and logging.
    'serviceAccounts': [{
        'email': 'default',
        'scopes': [
            'https://www.googleapis.com/auth/devstorage.read_write',
            'https://www.googleapis.com/auth/logging.write'
        ]
    }],

    # Metadata is readable from the instance and allows you to
    # pass configuration from deployment scripts to instances.
    'metadata': {
        'items': [{
            # Startup script is automatically executed by the
            # instance upon startup.
            'key': 'startup-script',
            'value': startup_script,
            'VIDEOPATH': videopath
        }]
    }
}

实例创建函数如下:

compute.instances().insert(
        project=project,
        zone=zone,
        body=config).execute()

Google 容器注册表 (GCR),用于存储 docker 图像,然后用于创建容器 NOT 计算引擎机器。

对于 Compute Engine,使用现有机器的 public 图像或自定义图像快照。

For Ref:- https://cloud.google.com/container-registry

希望对您有所帮助