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
- In the management console, select the folder to create your VM in.
- In the list of services, select Compute Cloud.
- Click Create VM.
- Under Public images, select a Container Optimized Image.
- 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:
- Enter the name of the Docker container to run on the VM.
- Specify the Docker image used to launch the Docker container on the VM.
- If necessary, fill in the remaining fields.
- 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
View a description of the CLI command to create a VM from a Container Optimized Image:
$ yc compute instance create-with-container --help
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-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 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 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.