Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • Yandex SIEM
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Setting up a Managed Service for PostgreSQL connection from a container in Serverless Containers
    • Creating a VM from a Container Optimized Image
    • Creating a VM from a Container Optimized Image with an additional volume for a Docker container
    • Creating an instance group from a Container Optimized Image with multiple Docker containers
    • Creating an instance group from a Container Optimized Image
    • Creating a VM from a Container Optimized Image with multiple Docker containers
    • Updating a Container Optimized Image VM
    • Configuring data output from a Docker container to a serial port
    • Running a Docker image on a VM using Cloud Registry

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create a VM specification file
  • Create a Docker container specification file
  • Get the ID of the image for creating the VM
  • Create a VM
  • Check the result
  • How to delete the resources you created
  1. Container infrastructure
  2. Configuring data output from a Docker container to a serial port

Configuring data output from a Docker container to a serial port

Written by
Yandex Cloud
Updated at August 6, 2026
View in Markdown
  • Get your cloud ready
    • Required paid resources
  • Create a VM specification file
  • Create a Docker container specification file
  • Get the ID of the image for creating the VM
  • Create a VM
  • Check the result
  • How to delete the resources you created

To create a VM from an image, such as a Container Optimized Image, and set up a redirect of the application output stream to the VM serial port:

  1. Get your cloud ready.
  2. Create a VM specification file.
  3. Create a Docker container specification file.
  4. Get the ID of the image for creating the VM.
  5. Create the VM.
  6. Check the result.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

If the Docker image you need is stored in Container Registry, create a service account with the container-registry.images.puller role for the registry in question. Your Container Optimized Image VM will use this account to pull the Docker image from the registry.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder used by default is the one specified when creating 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.

If you do not have a network or subnet, create them.

Required paid resourcesRequired paid resources

The infrastructure support cost includes:

  • Fee for a continuously running VM (see Yandex Compute Cloud pricing).
  • Fee for a dynamic or static external IP address (see Yandex Virtual Private Cloud pricing).

Create a VM specification fileCreate a VM specification file

CLI

Create a VM specification file named cloud-config-ports.yaml and paste the following into it:

#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_for_connecting_to_VM>

In the file configuration, set the username and specify the public part of the SSH key required to connect to the VM. You will need to create an SSH key pair by yourself.

Create a Docker container specification fileCreate a Docker container specification file

CLI

Create a Docker container specification file named container-spec-ports.yaml and paste the following into it:

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
  1. Create a VM with multiple disks.
    1. Get the ID of the image for creating the VM:

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

      yc compute instance create \
        --name coi-vm-with-sp \
        --zone ru-central1-a \
        --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 \
        --service-account-name <service_account_name>
      

      Where:

      • --name: VM name.

      • --zone: Availability zone.

      • --network-interface: VM network settings.

      • --metadata-from-file: YAML metadata files for creating the VM.

        Note

        The commands yc compute instance create | create-with-container | update | add-metadata support substitution of environment variable values into VM metadata. When you execute a Yandex Cloud CLI command, these values, specified in the user-data key in $<variable_name> format, will be substituted into the VM metadata from the environment variables of the environment the command is executed in.

        To change such behavior, i.e. to provide a variable name to the VM metadata in $<variable_name> format rather than take the variable value from the CLI command runtime environment, use the two-dollar syntax, e.g., $$<variable_name>.

        For more information, see Specifics of providing environment variables in metadata via the CLI.

      • --create-boot-disk: ID of the image to create a boot disk from.

      • --service-account-name: Name of the service account you created earlier.

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

    3. Check the result.

      1. In the management console, navigate to the folder dashboard and select Compute Cloud.
      2. Click the VM name: coi-vm-with-sp.
      3. Under Serial port, select the COM2 port. In a few minutes, the screen will display Hello world!.

Get the ID of the image for creating the VMGet the ID of the image for creating the VM

To get the ID of the latest image for creating the VM, run:

Linux (Bash)
Windows (PowerShell)
IMAGE_ID=$(yc compute image get-latest-from-family container-optimized-image \
  --folder-id standard-images \
  --format=json | jq -r .id)
$IMAGE_ID=(yc compute image get-latest-from-family container-optimized-image `
  --folder-id standard-images `
  --format=json | ConvertFrom-Json).id

Create a VMCreate a VM

CLI

Enter a name for the subnet where you will create your VM and run:

yc compute instance create \
  --name coi-vm-with-sp \
  --zone ru-central1-d \
  --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 for creating the VM.
  • --create-boot-disk: ID of the image to create a boot disk from.

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

Check the resultCheck the result

To check whether you correctly configured data output from the Docker container to the serial port:

  1. In the management console, navigate to the folder page.
  2. Navigate to Compute Cloud.
  3. Click the VM name: coi-vm-with-sp.
  4. Under Serial port, select the COM2 port. In a few minutes, the screen will display Hello world!.

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

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Delete the VM.
  2. Delete the VM’s public static IP address if you reserved one.

Was the article helpful?

Previous
Updating a Container Optimized Image VM
Next
Running a Docker image on a VM using Cloud Registry
© 2026 Direct Cursus Technology L.L.C.