[Yandex Cloud documentation](../../index.md) > [Yandex Compute Cloud](../index.md) > [Tutorials](index.md) > Container Optimized Image > Creating a VM from a Container Optimized Image with multiple Docker containers

# 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](../../cos/concepts/index.md) image. You will be creating your VM using the [Docker Compose specification](../../cos/concepts/coi-specifications.md#compose-spec).

## Getting started {#before-you-begin}

If the required Docker image has been pushed to Yandex Container Registry, create a [service account](../../iam/operations/sa/create.md) with the [container-registry.images.puller](../../container-registry/security/index.md#choosing-roles) role for the registry in use. A Container Optimized Image VM will pull the Docker image from the registry under this account.

## Create a VM with multiple Docker containers {#docker-compose}

{% list tabs group=instructions %}

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To create a Container Optimized Image VM with multiple Docker containers from:
  1. View the description of the CLI command for creating a Container Optimized Image VM:

     ```bash
     yc compute instance create-with-container --help
     ```

  1. Create a Docker container specification. Save the following data to the `docker-compose.yaml` file:

     ```yaml
     version: '3.7'
     services:
       app1:
         container_name: nginx
         image: "nginx"
         ports:
           - "80:80"
         restart: always
       app2:
         container_name: redis
         image: "redis"
         restart: always
     ```

  1. Create a VM with multiple Docker containers:

     ```bash
     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 <service_account_name> \
       --docker-compose-file docker-compose.yaml
     ```

     Where:
     * `--name`: VM name.
     * `--zone`: Availability zone.
     * `--ssh-key`: Path to the [public key](../operations/vm-connect/ssh.md#creating-ssh-keys) file and its name.
     * `--create-boot-disk size`: Boot disk size.

        To get the minimum boot disk size required for installing an image, run this command:
        * `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` property.

     * `--network-interface`: VM network settings.
     * `--service-account-name`: Name of the service account you created [earlier](#before-you-begin).
     * `--docker-compose-file`: YAML file with the container specification.

     Once created, the VM will appear in the VM list under **Compute Cloud** in the [management console](https://console.yandex.cloud).
  1. Check the result.
     1. [Connect to the VM over SSH](../operations/vm-connect/ssh.md).
     1. View the list of running Docker containers:

        ```bash
        sudo docker ps -a
        ```

        Result:

        ```text
        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
        ```

{% endlist %}