Configuring and Using KooCLI in Docker
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
- 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
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.
- Build an image.
Run the following command in the directory to create a Docker image named hcloudcli:
docker build --no-cache -t hcloudcli .
...
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
- 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:
- 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.
If the Docker image is created using a Dockerfile that contains ENTRYPOINT ["/usr/local/bin/hcloud"], docker run only supports KooCLI commands.
- 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.
- 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}
- 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}
- Run the following command to create a temporary container:
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.
- Method 1: Create a background container using the hcloudcli image and run commands in the container.
- 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.
- Remove the image.
Run the following command to remove the hcloudcli image:
docker rmi hcloudcli
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot