Creating a VM with Container Optimized Image
Create a VM from a Container Optimized Image and run a Docker container on it.
Getting started
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 Container Optimized Image VM will pull the Docker image from the registry on behalf of this account.
Create a VM with a Docker container from a Container Optimized Image image
-
In the management console
, select the folder to create your VM in. -
In the list of services, select Compute Cloud.
-
Click Create virtual machine.
-
Under Image/boot disk selection, go to the Container Solution tab.
-
Click Configure.
-
In the Docker container settings window that opens, set the parameters using suggestions:
- Specify the Docker image to be used to run the Docker container on the VM.
- Select the Restart policy field value for the Docker container:
- Always: Always restart the Docker container when it stops.
- Never: Do not restart the Docker container automatically.
- On-Failure: Restart the Docker container only if it shuts down with a non-zero return code.
- Fill out the remaining fields, if required.
Click Apply.
-
Set the remaining VM parameters by following this guide.
If you do not 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.
-
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 from a Container Optimized Image:
yc compute instance create-with-container \ --name my-vm \ --zone ru-central1-b \ --ssh-key ssh-key.pub \ --service-account-name my-robot \ --platform standard-v3 \ --create-boot-disk size=30 \ --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
Where:
--name
: VM name.--zone
: Availability zone.--ssh-key
: Contents of the public key file.--service-account-name
: Name of the service account.--create-boot-disk size
: Boot disk size. It must be at least 30 GB.--public-ip
: Public IP address allocated to the VM.--container-name
: Name of the Docker container.--container-image
: Name of the Docker image used to launch the Docker container.--container-command
: Command to run upon Docker container launch.--container-arg
: Parameters for the command specified in--container-command
.--container-env
: Environment variables available in the Docker container.--container-privileged
: Launching the Docker container in privileged mode.
Result:
done (17s) id: epdbf646ge5q******** folder_id: b1g88tflru0e******** created_at: "2023-03-13T09:44:03Z" name: my-vm ...
Once created, the VM will appear in the VM list under Compute Cloud in the management console
. For more information about working with VMs, see our step-by-step guides.
What's next
- Read a detailed description of a Container Optimized Image.
- To learn what else you can do with a Container Optimized Image, see our step-by-step guides.