Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Container Optimized Solutions
  • Getting started
  • Use cases
    • All use cases
    • Creating a VM from a Container Optimized Image
    • Creating a VM from a Container Optimized Image and an additional volume for a Docker container
    • Creating a VM from a Container Optimized Image with multiple Docker containers
    • Creating an instance group from a Container Optimized Image
    • Editing a VM with Container Optimized Image
    • Configuring data output from a Docker container to a serial port
    • Creating a VM and an instance group from a Container Optimized Image using Terraform
  • Concepts
    • Container Optimized Image
    • Quotas and limits
  • Pricing policy
  • Questions and answers
  1. Use cases
  2. Creating a VM from a Container Optimized Image

Creating a VM from a Container Optimized Image

  • Before you start
  • Create a VM with a Docker container built on 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

Management console
CLI using flags
CLI using a specification file
  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 Image/boot disk selection, go to the Container Solution tab.

  5. Click Configure.

  6. In the Docker container settings window that opens, set parameters using hints:

    • (optional) Enter the Name of the Docker container to run on the VM. Naming requirements:
      • The length can be from 3 to 63 characters.
      • It may contain Latin letters, numbers, and hyphens.
      • The first character must be a letter. The last character can't be a hyphen.
    • Specify the Docker image used to launch the Docker container on the VM.
    • (optional) In the Command field, specify the executable file to run when the Docker container starts.
    • (optional) Specify Command arguments.
    • (optional) Specify Environment variables in key:value format, which are available in the Docker container.
    • Select the Restart policy field value for the Docker container:
      • Always: Always restart the Docker container when it's stopped.
      • Never: Don't restart the Docker container automatically.
      • On-Failure: Restart the Docker container only if it shut down with a non-zero return code.
    • (optional) Enable Attach a TTY to the Docker container to use the command shell in the Docker container.
    • (optional) Enable Allocate an stdin buffer for a running Docker container to link the input stream to the running Docker container.
    • (optional) Enable Run Docker container in privileged mode to allow the Docker container processes to access all VM resources.

    Click Apply.

  7. Configure the other VM settings based on the instructions.

If you don't have the Yandex.Cloud command line interface yet, install and initialize 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.

To create a VM and set Docker container parameters via the YC CLI:

  1. View a description of the command:

    yc compute instance create-with-container --help
    
  2. Run the command:

    yc compute instance create-with-container
     --name my-vm \
     --zone=ru-central1-b \
     --ssh-key ssh-key.pub \
     --service-account-name my-robot \
     --public-ip \
     --container-name=my-app \
     --container-image=cr.yandex/mirror/ubuntu:16.04 \
     --container-command=sleep \
     --container-arg="1000" \
     --container-env=KEY1=VAL1,KEY2=VAL2 \
     --container-privileged
    

    Command 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.

    Command results:

    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.

If you don't have the Yandex.Cloud command line interface yet, install and initialize 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.

To create a VM and set Docker container parameters using a specification file:

  1. View a description of the command:

    yc compute instance create-with-container --help
    
  2. Create a Docker container specification file. Save the following data to a file named docker-spec.yaml:

    spec:
      containers:
      - command:
        - sleep
        args:
        - 100000
        image: cr.yandex/mirror/ubuntu:20.04
        name: my-container
        securityContext:
          privileged: true
    
  3. Run the command:

    yc compute instance create-with-container \
      --coi-spec-file docker-spec.yaml \
      --name my-vm \
      --zone=ru-central1-b \
      --ssh-key ssh-key.pub \
      --service-account-name my-service-account \
      --public-ip
    

    Command parameters:

    • --coi-spec-file is the path to the Docker container specification file.
    • --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.

    Command results:

    done (1m40s)
     id: epde18u4mahl4a8n39ta
     folder_id: b1g7gvsi89m34qmcm3ke
     created_at: "2020-08-10T13:50:17Z"
     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.

In this article:
  • Before you start
  • Create a VM with a Docker container built on a Container Optimized Image
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC