Oracle Cloud Infrastructure (OCI) provides a powerful command line interface called OCI CLI that allows administrators, developers, and cloud engineers to manage cloud resources directly from the terminal.
OCI CLI is extremely useful for:
- Cloud automation
- Managing compute instances
- Working with Object Storage
- Managing networking resources
- Database administration
- Terraform integrations
- Scripting and DevOps operations
What is OCI CLI?
OCI CLI stands for:
Oracle Cloud Infrastructure Command Line Interface
It allows you to interact with OCI services using commands instead of the web console.
OCI CLI Command Structure
Most OCI CLI commands follow this structure:
oci <service> <resource> <action>
Example
oci iam region list
Breakdown:
- iam → OCI Identity service
- region → Resource type
- list → Action
Check OCI CLI Installation
To verify OCI CLI is installed:
oci --version
Display OCI CLI Help
oci --help
or simply:
oci
Useful Global OCI CLI Options
| Option | Description |
|---|---|
| --help | Show help information |
| --version | Display OCI CLI version |
| --output table | Display output in table format |
| --debug | Enable debug output |
| --region | Specify OCI region |
| -i | Interactive mode |
Enable Interactive Mode
OCI CLI supports interactive mode for auto-completion and easier command discovery.
oci -i
Basic OCI Commands
1. List OCI Regions
oci iam region list
2. Display Output in Table Format
oci iam region list --output table
3. Get Current Object Storage Namespace
oci os ns get
4. List Compartments
oci iam compartment list --all
5. List Availability Domains
oci iam availability-domain list
Working with Compute Instances
List Compute Instances
oci compute instance list \ --compartment-id <compartment_ocid>
Get Instance Details
oci compute instance get \ --instance-id <instance_ocid>
Start a Compute Instance
oci compute instance action \ --instance-id <instance_ocid> \ --action START
Stop a Compute Instance
oci compute instance action \ --instance-id <instance_ocid> \ --action STOP
Working with Object Storage
List Buckets
oci os bucket list \ --compartment-id <compartment_ocid> \ --namespace-name <namespace>
Create a Bucket
oci os bucket create \ --compartment-id <compartment_ocid> \ --name mybucket \ --namespace-name <namespace>
Upload a File
oci os object put \ --bucket-name mybucket \ --file test.txt
List Objects Inside Bucket
oci os object list \ --bucket-name mybucket
Working with Networking
List Virtual Cloud Networks (VCNs)
oci network vcn list \ --compartment-id <compartment_ocid>
List Subnets
oci network subnet list \ --compartment-id <compartment_ocid>
List Internet Gateways
oci network internet-gateway list \ --compartment-id <compartment_ocid>
Working with Databases
List Autonomous Databases
oci db autonomous-database list \ --compartment-id <compartment_ocid>
List DB Systems
oci db system list \ --compartment-id <compartment_ocid>
Using Queries in OCI CLI
OCI CLI supports JMESPath queries for filtering output.
Example
oci iam compartment list \ --all \ --query "data[*].name"
Get Only OCIDs
oci iam compartment list \ --all \ --query "data[*].id"
Using Raw Output
oci os ns get --query data --raw-output
This returns only the namespace value without JSON formatting.
Generate JSON Templates
OCI CLI can automatically generate JSON input templates.
Example
oci os bucket create \ --generate-full-command-json-input
Working with Configuration Files
OCI CLI configuration file location:
~/.oci/config
Typical configuration:
[DEFAULT] user=ocid1.user.oc1... fingerprint=xx:xx:xx tenancy=ocid1.tenancy.oc1... region=ap-mumbai-1 key_file=/home/opc/.oci/oci_api_key.pem
OCI CLI Authentication Types
OCI CLI supports multiple authentication methods:
| Authentication Type | Description |
|---|---|
| api_key | Standard API key authentication |
| instance_principal | Authentication from OCI compute instances |
| security_token | Token-based authentication |
| resource_principal | Used for OCI services and functions |
OCI Cloud Shell Advantage
OCI Cloud Shell already includes:
- OCI CLI pre-installed
- Authentication pre-configured
- Terraform tools
- kubectl
- Git
- Python SDKs
This makes it very easy to start working with OCI immediately.
Useful Troubleshooting Commands
Enable Debugging
oci --debug iam region list
Check Current Region
cat ~/.oci/config
Validate Authentication
oci iam region list
Best Practices
- Use OCI CLI interactive mode for learning
- Store scripts securely
- Avoid exposing OCIDs publicly
- Use instance principals where possible
- Use table output for readability
- Use queries to simplify output
Conclusion
OCI CLI is one of the most powerful tools available for managing Oracle Cloud Infrastructure resources.
With simple commands, administrators can manage:
- Compute instances
- Networking
- Object Storage
- Databases
- Kubernetes
- Security services
Combined with Oracle Cloud Shell, OCI CLI becomes an excellent platform for automation, cloud administration, and DevOps operations.
Learning basic OCI commands is the first step toward mastering Oracle Cloud Infrastructure administration and automation.
No comments:
Post a Comment