Creating a VM with a Container Optimized Image

Create a VM from a Container Optimized Image and run a Docker container on it.

Before you start

If the required Docker image is pushed to Container Registry, create a service account with the container-registry.images.puller role for the registry in use. A VM with a Container Optimized Image pulls the Docker image from the registry on behalf of this account.

Create a VM with a Docker container built on a Container Optimized Image

  1. In the management console, select the folder to create your VM in.
  2. In the list of services, select Compute Cloud.
  3. Click Create VM.
  4. Under Public images, select a Container Optimized Image.
  5. The Docker container settings section appears at the bottom of the VM creation page. Fill out this section based on the prompts next to each field:
    1. Enter the name of the Docker container to run on the VM.
    2. Specify the Docker image used to launch the Docker container on the VM.
    3. If necessary, fill in the remaining fields.
  6. Configure the other VM settings based on these instructions.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. View a description of the CLI command to create a VM from a Container Optimized Image:

    $ yc compute instance create-with-container --help
  2. Create a VM using the following parameters:

    • --name: VM name.
    • --zone: Availability zone.
    • --ssh-key: Contents of the public key file.
    • --service-account-name: Service account name.
    • --public-ip: Public IP address allocated to the VM.
    • --container-name: The name of the Docker container.
    • --container-image: The name of the Docker image used to launch the Docker container.
    • --container-command: The command to run upon Docker container launch.
    • --container-arg: Parameters for the command specified in --container-command.
    • --container-env: The environment variables available in the Docker container.
    • --container-privileged: Launch the Docker container in privileged mode.
    $ yc compute instance create-with-container
    --name my-vm \
    --zone=ru-central1-b \
    --ssh-key \
    --service-account-name my-robot \
    --public-ip \
    --container-name=my-app \ \
    --container-command=sleep \
    --container-arg="1000" \
    --container-env=KEY1=VAL1,KEY2=VAL2 \
    done (17s)
    id: epdbf646ge5qgutfvh43
    folder_id: b1g88tflru0ek1omtsu0
    created_at: "2019-08-07T09:44:03Z"
    name: my-vm
    zone_id: ru-central1-b
    platform_id: standard-v2

Once the VM is created, it appears in the list of VMs under Compute Cloud in the management console.

For more information about working with VMs, see our step-by-step instructions.