Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Container Optimized Solutions
  • 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
    • 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
  • Concepts
    • Container Optimized Image
    • Quotas and limits
  • Pricing policy
  • Questions and answers
  1. Use cases
  2. Configuring data output from a Docker container to a serial port

Configuring data output from a Docker container to a serial port

  • Before you start
  • Create a VM from a Container Optimized Image with serial port output

In this tutorial, you'll create a VM from a Container Optimized Image and set up a redirect of the application output stream to the VM serial port.

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 from a Container Optimized Image with serial port output

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.

  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 VM specification file. Specify the username, set the public part of the SSH key to connect to the VM, and save this data to a file named cloud-config-ports.yaml:

    #cloud-config
    runcmd:
      - [ sudo, chmod, 666, /dev/ttyS1]
    users:
      name: <username>
        groups: sudo
        shell: /bin/bash
        sudo: ['ALL=(ALL) NOPASSWD:ALL']
        ssh-authorized-keys:
          - <public SSH key to connect to the VM>
    
  3. Create a Docker container specification file. Save the following data to a file named container-spec-ports.yaml:

    spec:
     containers:
     - image: ubuntu
       name: app
       command: ["/bin/bash", "-c", "sleep 30 && echo 'Hello World!' > /dev/ttyS1"]
       securityContext:
         privileged: true
       stdin: false
       tty: false
       volumeMounts:
         - mountPath: /dev/ttyS1
           name: log-port
     restartPolicy: Always
     volumes:
       - name: log-port
         hostPath:
           path: /dev/ttyS1
    
  4. Create a VM with multiple disks.

    1. Get the ID of the image to create the VM:

      • Bash

        $ IMAGE_ID=$(yc compute image get-latest-from-family container-optimized-image --folder-id standard-images --format=json | jq -r .id)
        
      • PowerShell

        > $IMAGE_ID=(yc compute image get-latest-from-family container-optimized-image --folder-id standard-images --format=json | ConvertFrom-Json).id
        
    2. Create a VM:

      yc compute instance create \
          --name coi-vm-with-sp \
          --zone=ru-central1-c \
          --network-interface subnet-name=<subnet name>,nat-ip-version=ipv4 \
          --metadata-from-file user-data=cloud-config-ports.yaml,docker-container-declaration=container-spec-ports.yaml \
          --create-boot-disk image-id=$IMAGE_ID
      

      Where:

      • --name: VM name.
      • --zone: Availability zone.
      • --network-interface: VM network settings.
      • --metadata-from-file: YAML metadata files to create the VM.
      • --create-boot-disk: ID of the image to create a boot disk from.

      Once the VM is created, it appears in the list of VMs under Compute Cloud in the management console.

    3. Check the results.

      1. In the management console, go to the folder page and select Compute Cloud.
      2. Click on the name of the VM coi-vm-with-sp.
      3. Under Serial port, select COM2. In a few minutes, the screen displays Hello world!.

For more information about working with VMs, see our step-by-step instructions.

In this article:
  • Before you start
  • Create a VM from a Container Optimized Image with serial port output
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC