Run the IDCF cloud CLI with Docker

I've previously looked at Design Patterns for Running CLI on Docker Container, but this time IDCF Cloud CLI Let's make an image of .jp / cloud / spec / api.html). You can prepare a virtual environment with virtuanemv, but if you distribute commands with a Docker image, you can try it without polluting the environment of the host machine. You can do it. The Docker image can also be conveniently used as a CLI distribution format.

project

The repository created this time is here.

Dockerfile

The base image uses 2.7 ON BUILD of the official Python. The Dockerfile is very easy because ONBUILD does the necessary processing for the build.

Dockerfile


FROM python:2-onbuild

requirements.txt

The IDCF Repository does not include requirements.txt. Define the addition of dependent packages and cloudstack-api to be installed via GitHub as well.

requirements.txt


httplib2
simplejson
argparse
prettytable==0.5
parsedatetime==0.8.7
lxml
-e git+https://github.com/idcf/cloudstack-api#egg=cloudstack-api

The ONBUILD base image will COPY and pip install the requirements.txt file.

Dockerfile


FROM python:2.7

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ONBUILD COPY requirements.txt /usr/src/app/
ONBUILD RUN pip install --no-cache-dir -r requirements.txt

ONBUILD COPY . /usr/src/app

docker-compose.yml

Set environment variables from the IDCF Cloud Console API Key (https://console.idcfcloud.com/user/apikey).

docker-compose.yml


idcfcli:
  build: .
  volumes:
    - /etc/localtime:/etc/localtime:ro
  environment:
    - IDCF_COMPUTE_HOST=
    - IDCF_COMPUTE_API_KEY=
    - IDCF_COMPUTE_SECRET_KEY=
  command: ["/usr/local/bin/cloudstack-api","listVirtualMachines","-t=id,name,state"]

How to use

git clone from the repository. Rename docker-compose.yml.default to docker-compose.yml and set the environment variables.

$ git clone https://github.com/masato/docker-idcfcli.git idcfcli
$ cd idcfcli
$ mv docker-compose.yml.default docker-compose.yml
$ vi docker-compose.yml

Start the container from Docker Compose. The default command is running listVirtualMachines.

$ docker-compose build
$ docker-compose run --rm idcfcli
+--------------------------------------+------+---------+
|                  id                  | name |  state  |
+--------------------------------------+------+---------+
| xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | seed | Running |
+--------------------------------------+------+---------+

Execute any command as follows.

$ docker-compose run --rm idcfcli cloudstack-api listVirtualMachines -t=id,name,state
+--------------------------------------+------+---------+
|                  id                  | name |  state  |
+--------------------------------------+------+---------+
| xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | seed | Running |
+--------------------------------------+------+---------+

Creating an alias

Define an alias in ~ / .bashrc etc.

~/.bashrc


alias idcf-cli='docker-compose run --rm idcfcli cloudstack-api'

Using aliases makes it more CLI-like.

$ idcf-cli listVirtualMachines -t=id,name,state
+--------------------------------------+------+---------+
|                  id                  | name |  state  |
+--------------------------------------+------+---------+
| xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | seed | Running |
+--------------------------------------+------+---------+

Recommended Posts

Run the IDCF cloud CLI with Docker
The day of docker run (note)
Run the app with Flask + Heroku
Run XGBoost with Cloud Dataflow (Python)
Access the Docker Remote API with Requests
Behind the flyer: Using Docker with Python
Run the original YOLO with Jetson Nano
Use Tabpy with Cloud Run (on GKE)
Run the interaction model with Attention Seq2 Seq
Run a Python web application with Docker
Scraping the holojour and displaying it with CLI
Note: Prepare the environment of CmdStanPy with docker
Get the latest AMI information with the AWS CLI
Prepare the execution environment of Python3 with Docker
Easily realize microservices with Cloud Run x Flask
Run the flask app on Cloud9 and Apache Httpd
Change the time zone with Docker in Oracle Database
Run a machine learning pipeline with Cloud Dataflow (Python)
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
Preparing the execution environment of PyTorch with Docker November 2019
Run Google Cloud Functions locally with Cloud Native Build packs
Tftp server with Docker
Run Python with VBA
Run prepDE.py with python3
Run Blender with python
Use python with docker
Proxy server with Docker
Hello, World with Docker
Point Cloud with Pepper
Cloud Run tutorial (python)
Run iperf with python
Specify the project name of docker-compose with Docker integration of Pycharm
Run the intellisense of your own python library with VScode.
Make a SonicWall SSL VPN connection with the Linux CLI
Download the raw link of GitLab private repository with CLI
I noticed while trying to run ninix-aya with Docker (Part 3)
Touch NoSQL with Python using the Oracle NoSQL Database Cloud Simulator
The true value of Terraform automation starting with Oracle Cloud
Get the host name of the host PC with Docker on Linux