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

时间:2020-05-25 00:55:53

标签: docker google-cloud-platform google-compute-engine gcloud google-container-registry

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

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()

1 个答案:

答案 0 :(得分:3)

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

对于Compute Engine,请使用现有计算机的公共映像或自定义映像快照。

对于裁判:-https://cloud.google.com/container-registry

希望这会有所帮助