Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Container Solution
  • Comparison with other Yandex Cloud services
  • Getting started
  • Use cases
    • All use cases
    • Creating a VM from a Container Optimized Image
    • Creating a VM from a Container Optimized Image and an additional volume for a Docker container
    • Creating a VM from a Container Optimized Image with multiple Docker containers
    • Creating an instance group from a Container Optimized Image
    • Creating an instance group from a Container Optimized Image with multiple Docker containers
    • Editing a VM with Container Optimized Image
    • Configuring data output from a Docker container to a serial port
    • Creating a VM and an instance group from a Container Optimized Image using Terraform
    • Transferring logs from COI to Cloud Logging
  • Concepts
    • Container Optimized Image
    • Specifics of working with a boot disk
    • Specifics of working with the network
    • Docker image
    • Policies for restarting a Docker container
    • Docker container specifications
    • Quotas and limits
  • COI releases
  • Pricing policy
  • Questions and answers
  • Troubleshooting
  1. Use cases
  2. Creating a VM from a Container Optimized Image with multiple Docker containers

Creating a VM from a Container Optimized Image with multiple Docker containers

Written by
Yandex Cloud
  • Before you start
  • Create a VM with multiple Docker containers

In this tutorial, you'll create a VM that contains multiple Docker containers from a Container Optimized Image. A VM is created based on the Docker Compose specification.

Before you start

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 VM with a Container Optimized Image pulls the Docker image from the registry on behalf of this account.

Create a VM with multiple Docker containers

CLI

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 with multiple Docker containers from a Container Optimized Image:

  1. View a description of the CLI command to create a VM from a Container Optimized Image:

    yc compute instance create-with-container --help
    
  2. Create a Docker container specification. Save the following data to a file named docker-compose.yaml:

    version: '3.7'
    services:
      app1:
        container_name: nginx
        image: "nginx"
        ports:
          - "80:80"
        restart: always
      app2:
        container_name: redis
        image: "redis"
        restart: always
    
  3. 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 \
      --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: Contents of the public key file.
    • --network-interface: VM network settings.
    • --service-account-name: Service account name.
    • --docker-compose-file: YAML file with the container specification.

    After being created, the VM will appear in the VM list under Compute Cloud in the management console.

  4. Check the results.

    1. Connect to the VM via SSH.

    2. View a list of running Docker containers:

      sudo docker ps -a
      

      Result:

      CONTAINER ID  IMAGE  COMMAND                 CREATED         STATUS         PORTS               NAMES
      c79b1cdc5a3a  nginx  "nginx -g 'daemon of…"  16 seconds ago  Up 14 seconds  0.0.0.0:80->80/tcp  nginx
      3ac5a9844a5d  redis  "docker-entrypoint.s…"  2 minutes ago   Up 2 minutes   6379/tcp            redis
      

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Before you start
  • Create a VM with multiple Docker containers