Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Configuring and Using KooCLI in Docker

Updated on 2024-06-12 GMT+08:00

Configure and use KooCLI in Docker by performing the following steps. This procedure uses a Docker container running Ubuntu Linux as an example.

Before performing the following steps, ensure that you have installed Docker. For details about how to install Docker, visit the Docker website. To check whether Docker has been installed, run the following command:

docker --version

  1. Create a Dockerfile.

    Create a directory and create a text file named Dockerfile in the directory. The file content is as follows:

    FROM ubuntu:latest
    RUN apt-get update -y && apt-get install curl -y
    # Install KooCLI with one click.
    RUN curl -sSL https://ap-southeast-3-hwcloudcli.obs.ap-southeast-3.myhuaweicloud.com/cli/latest/hcloud_install.sh -o ./hcloud_install.sh && bash ./hcloud_install.sh -y
    WORKDIR hcloud
    NOTE:

    The name of the Dockerfile contains an uppercase letter D and does not have an extension. Only one Docker file can be saved in each directory.

    hcloud_install.sh is the script file for installing KooCLI in one click. The corresponding software package verification file is hcloud_install.sh.sha256.

    Add the following content to the preceding Dockerfile to specify KooCLI as the program to run when the container is started:

    ENTRYPOINT ["/usr/local/bin/hcloud"]

    The container started by the Docker image built using this file (see Method 2) supports only a single KooCLI command.

  2. Build an image.

    Run the following command in the directory to create a Docker image named hcloudcli:

    docker build --no-cache -t hcloudcli .

    ...

    NOTE:

    The period (.) at the end of the command cannot be omitted. It indicates that the Docker image is built in the current directory.

    After you add ENTRYPOINT ["/usr/local/bin/hcloud"] to the Dockerfile, the following information is displayed when you build an image:

    After the image is built successfully, run the following command to view the image:

    docker images

  3. Use the image.

    • Method 1: Create a background container using the hcloudcli image and run commands in the container.
      docker run -it -d --name hcloudcli hcloudcli

      Run the following command to view the started Docker container:

      docker ps

      Run the following command to enter the Docker container. Then you can use KooCLI in the same way as you use it on the host.

      docker exec -it hcloudcli /bin/bash

      Run the following command to exit the hcloudcli container:

      exit

      To stop the hcloudcli container, run the following command:

      docker stop hcloudcli
    • Method 2: Create a temporary container using the hcloudcli image:
      1. Run the following command to create a temporary container:
        docker run --rm -it hcloudcli ${command}
        • If the Docker image is created using a Dockerfile that does not contain ENTRYPOINT ["/usr/local/bin/hcloud"], specify hcloud as the program to run in the docker run command, as shown in the following figure.

        • If the Docker image is created using a Dockerfile that contains ENTRYPOINT ["/usr/local/bin/hcloud"], you do not need to specify a program to run. In this case, running the docker run --rm -it hcloudcli command is equivalent to running the hcloud command on the host, as shown in the following figure.

          NOTE:

          If the Docker image is created using a Dockerfile that contains ENTRYPOINT ["/usr/local/bin/hcloud"], docker run only supports KooCLI commands.

      2. Create a temporary container and share files of a host (for example, a host running Linux) with the container.

        Mount a host directory to a container directory to share files of the host with the container.

        Example 1: Mount the /root/.hcloud/ directory of the host to the /root/.hcloud/ directory of the container to share the host configuration file with the container.

        docker run --rm -it -v /root/.hcloud/:/root/.hcloud/ hcloudcli ${command}

        Example 2: Mount the /cli directory of the host to the current directory of the container to share the test.json file of the host with the container.

        docker run --rm -it -v /root/.hcloud/:/root/.hcloud/ -v /cli:$(pwd) hcloudcli ${command}

      3. Create a temporary container and share an environment variable of a host (for example, a host running Linux) with the container.

        Use -e to mark the environment variable to be shared with the container.

        docker run --rm -it -e ${envName} hcloudcli ${command}
    NOTE:

    Set an alias for the command (a host running Linux is used as an example). For example, a Docker image has been created using a Dockerfile that contains ENTRYPOINT ["/usr/local/bin/hcloud"]. Run the following command to set the alias hcloud for the original command:

    alias hcloud='docker run --rm -it hcloudcli'

    Then you can run the original command using the alias. See the following figure.

  4. Update the image.

    The KooCLI version in the image is the latest version when the image is created. To ensure that the image uses the latest version, rebuild the image.

  5. Remove the image.

    Run the following command to remove the hcloudcli image:

    docker rmi hcloudcli

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback