Creating a VM from a Container Optimized Image with multiple Docker containers
In this tutorial, you will create a VM with multiple Docker containers from a Container Optimized Image image. A VM is created based on the Docker Compose specification.
Getting started
If the required Docker image is pushed to Yandex 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 multiple Docker containers
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
To create a VM with multiple Docker containers from a Container Optimized Image:
-
View the description of the CLI command to create a VM from a Container Optimized Image:
yc compute instance create-with-container --help
-
Create a Docker container specification. Save the following data to the
docker-compose.yaml
file:version: '3.7' services: app1: container_name: nginx image: "nginx" ports: - "80:80" restart: always app2: container_name: redis image: "redis" restart: always
-
Create a VM with multiple Docker containers:
yc compute instance create-with-container \ --name my-vm \ --zone ru-central1-a \ --ssh-key ssh-key.pub \ --create-boot-disk size=30 \ --network-interface subnet-name=<subnet_name>,nat-ip-version=ipv4 \ --service-account-name default-sa \ --docker-compose-file docker-compose.yaml
Where:
-
--name
: VM name. -
--zone
: Availability zone. -
--ssh-key
: Path to the public key file and its name. -
--create-boot-disk size
: Boot disk size.To find out the minimum boot disk size required to install the image, run one of these commands:
yc compute image get-latest-from-family container-optimized-image --folder-id standard-images
if you are installing a Container Optimized Image.yc compute image get-latest-from-family container-optimized-image-gpu --folder-id standard-images
if you are installing a GPU Container Optimized Image.
You can find the minimum boot disk size in the
min_disk_size
parameter. -
--network-interface
: VM network settings. -
--service-account-name
: Service account name. -
--docker-compose-file
: YAML file with container specification.
Once created, the VM will appear in the VM list under Compute Cloud in the management console
. -
-
Check the result.
-
View a list of running Docker containers:
sudo docker ps -a
Result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c79b******** nginx "nginx -g 'daemon of…" 16 seconds ago Up 14 seconds 0.0.0.0:80->80/tcp nginx 3ac5******** redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 6379/tcp redis