Oracle Cloud Infrastructure (OCI) command line interface (CLI) is one of several methods provided for managing the Oracle cloud infra generation 2.
The CLI can be installed and configured in your local machine just following the instructions in the documentation.
In this post, we are explaining an alternate method for using the CLI by means of creating a container. Main advantage: portability and encapsulation of configurations just in case you are managing more than one tenant.
STEP 1
Install and configure OCI CLI. Please notice that a hidden folder called .oci gets created in your home directory:
STEP 2
Create a directory for creating the container, let’s call it ocloudshell for instance:
mkdir ocloudshell
STEP 3
copy ./oci directory in your home directory to ocloudshell dir
STEP 4
Edit the ./oci/config file and change the absolute paths to be relative to the home directory. For instance, in my mac is as follows:
STEP 5
Download the OPC CLI and put it in the ocloudshell dir
STEP 6
Create Dockerfile as follows:
FROM store/oracle/serverjre:8 ENV LC_ALL=en_US.utf8 \ LANG=en_US.utf8 ARG OPC_CLI_VERSION=18.1.2 ENV OPC_CLI_PKG=opc-cli-$OPC_CLI_VERSION.zip WORKDIR /ocloudshell/ RUN curl -o /etc/yum.repos.d/public-yum-ol7.repo http://yum.oracle.com/public-yum-ol7.repo \ && yum-config-manager --enable ol7_developer_EPEL \ && yum-config-manager --enable ol7_developer \ && yum -y install unzip python-oci-cli \ && rm -rf /var/cache/yum/* WORKDIR /root ADD .oci/ .oci/ RUN chmod 400 .oci/config RUN chmod 400 .oci/oci_api_key.pem CMD ["/bin/bash"]
STEP 7
docker build -t myrepo/ocloudshell . docker push myrepo/ocloudshell
TEST IT
So far, so good. Let’s test the container executing a command, here is the command reference documentation. For instance, let’s execute a command for starting a VM:
docker run -it javiermugueta/ocloudshell oci compute instance action --instance-id ocid1.instance.oc1.eu-frankfurt-1.abtheljtbocj2w4qywieacalgsortabg4kep77lplqfwfmlup77725rvsjxa --action start
That’s all folks!
Enjoy 🙂
One Comment