Creating a VM from 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 Image/boot disk selection, go to the Container Solution tab.
-
Click Configure.
-
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.
- (optional) Enter the Name of the Docker container to run on the VM. Naming requirements:
-
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:
-
View a description of the command:
yc compute instance create-with-container --help
-
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:
-
View a description of the command:
yc compute instance create-with-container --help
-
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
-
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.