This topic provides a walk-through of the commands required to launch a Linux
instance and a Windows instance. This tutorial includes working with a compartment, creating
a virtual cloud network, and launching instances.
Tip
The CLI has an interactive mode that provides automatic command completion and parameter information and suggestions. For more information, see Using Interactive Mode.
About the Command Line Interface (CLI)
The CLI is a tool that lets you work with most of the available services in Oracle Cloud Infrastructure. The CLI provides the same core functionality as the Console, plus additional commands. The CLI's functionality and command help are based on the service's API.
Getting Help with Commands 🔗
You can get inline help using the --help, -h, or -? keywords. For
example:
This response to the oci os ns get command shows the
standard output, which is returned in JSON format. JSON objects are written
as key/value pairs, with the key and value separated by a colon. For
example:
A key like "id" isn't very informative. To
understand the JSON object reference you have to read the key's value.
{
"data": "docs"
}
Most of the command and response groups in this guide aren't as simple as the preceding example. However, as you work through the tasks, they are easier to read and work with.
Before You Begin 🔗
Before you start using the command line interface, verify that you meet all the requirements described in Command Line Interface (CLI).
As a best practice, complete the tasks in this tutorial in a test environment. This approach ensures that your configurations do not affect other environments in the tenancy. At the end of the tutorial, you can safely delete the test resources.
Working in a Compartment 🔗
In this tutorial, you use one compartment for all your resources. When you are ready to create a production environment, you will most likely separate these resources in different compartments.
You can either use an existing compartment (recommended), or create a new compartment.
Choose a Compartment 🔗
Help: oci iam compartment list -h
To list the compartments in your tenancy, run the following command.
Before you create a compartment, review Working with Compartments to understand compartment design, resource management, and compartment constraints. (For IAM without identity domains, see Working with Compartments.)
To create a compartment, run the following command.
Copy
oci iam compartment create --name <compartment_name> -c <root_compartment_id> --description "<friendly_description>"
Keep track of the information that's returned when you run commands. In several cases, you need this information as you work through this document. For example, the preceding command returns the OCID for the tenancy, which is also the root compartment.
Before you can launch any instances, you have to create a virtual cloud network (VCN) and related resources. The following tasks are used to prepare the network environment:
Create the Virtual Cloud Network
Help: oci network vcn create -h
Create the VCN, specifying a DNS name and a CIDR block range.
When you create a VCN, a default security list is created for you. However, the Windows instance also requires inbound traffic enabled for port 3389. The preferred approach is creating a second list that addresses the Windows port requirement. You use the --security-list-ids option to associate both security lists with the subnet when you create it.
Note
Passing JSON Strings in the CLI
The next command passes complex input as a JSON text string. For help with formatting JSON input, especially when working in a Windows environment, see Passing Complex Input.
To create a new security list and configure the ingress rule for port 3389, run the following command.
Help: oci iam availability-domain list -h, oci network subnet create -h
In this next step, you have to provide the OCIDs for the default security list and the new security list. If you didn't record these OCIDs, use the oci network security-list list command to get a list of the security lists in the virtual cloud network.
Before you create a subnet, you have to find out which availability domains are available to create the subnet in.
To get the availability domain list for your compartment, run the following command.
Copy
oci iam availability-domain list -c <compartment_id>
The information in the previous response shows that there is a route table without any rules: "route rules":[]. Because the table exists, you create a rule by updating the table. When you run the next command, you get a warning about updates to route rules. Any update to the route rules replaces all the existing rules. If you want to continue and process the update, Enter "y".
To update the route rules, run the following command.
Copy
oci network route-table update --rt-id <route_table_id> --route-rules "[{"cidrBlock":"<0.0.0.0/0>","networkEntityId":"<internet_gateway_id>"}]
WARNING: Updates to route-rules will replace any existing values. Are you sure you want to continue? [y/N]: y
oci network route-table update --rt-id ocid1.routetable.oc1.phx.aaaaaaaagdjqga3i6qrxvf23stedpre4rmkdrw6qeqkftjtzyn7vctmujo2q --route-rules "[{"cidrBlock":"0.0.0.0/0","networkEntityId":"ocid1.internetgateway.oc1.phx.aaaaaaaa3vcd7gmqqh4po6wnsjhcdkxlddeqinmnbanzz2wsh5gdrwt574ka"}]
WARNING: Updates to route-rules will replace any existing values. Are you sure you want to continue? [y/N]: y
The shape identifies the configuration of the virtual machine or bare metal host that you want to use. Compute Shapes contains up-to-date information about the available shapes.
For the purposes of this walk-through, use this virtual machine shape for testing: --shape "VM.Standard1.1". This shape is configured with 1 CPU and 7 GB of memory.
Note
Shape and Block Volume Sizing
Sizing for compute instance shapes and block volumes are not part of this walk-through. The examples use the minimum sizes that are available.
To get a list of all the available bare metal and virtual machine shapes, run the following command.
Copy
oci compute shape list -c <compartment_id> --availability-domain "<availability_domain_name>"
Now you're ready to launch a Linux instance based on the configurations you prepared.
Use a Public/Private Key Pair to Connect to the Instance
When you launch an instance using the CLI, you need an existing key pair to access the instance. (This key pair is not the same as an API signing key.)
Launch the Instance
Help: oci compute instance launch -h
Caution
In this example, the --ssh-authorized-keys-file parameter references a file that contains the public key required to access the compute instance. If you don't provide this key when you launch the instance you can't connect to the instance after it's launched.
To launch the Linux instance, run the following command.
After the lifecycle state changes from "PROVISIONING" to "AVAILABLE" you can attach the volume to the Linux instance.
Tip
Finding out the Lifecycle State
You can find out the lifecycle state for the block volume using the oci bv volume get command for the volume you created. You can also query other resources such as compute instances and VNICs, to find out their lifecycle state.
Attach the Block Volume to the Instance
Help: oci compute volume-attachment attach -h
To attach the block volume to the Linux instance, run the following command.
Launching a Windows instance follows the same pattern and requires the same information as launching a Linux instance. The only significant differences are the operating system and shape, as shown in the following commands.
Launch the Instance
Help: oci compute instance launch -h
To launch the Windows instance, run the following command.
Although the Public IP address is required for connecting to Linux and Windows instances, that is the only thing the two have in common. Some of these differences include: authentication, port configuration, and desktop client programs.
When you've finished setting up the test environments described in this tutorial, clean up the test environment by removing resources you aren't using.
Detach and Delete the Block Volumes
Help: oci compute volume-attachment list -h , oci compute volume-attachment detach -h and oci bv volume delete -h
Removing a block volume from an instance is a 3-step process. Use the following steps to detach and delete the block volume for the Linux instance.
Get the volume-attachment-id
The volume attachment ID is created when you create a block volume.
To get the volume attachment ID, run the following command.
Copy
oci compute volume-attachment list -c <compartment_id>
Are you sure you want to delete this resource? [y/N]:
All destructive actions, such as detaching and deleting
resources allow you to use the --force
parameter, and the resource is removed without requiring
confirmation. As a best practice, use the y/N option instead
of --force.
Confirm the deletion. No response is returned after the resource
is deleted.
Delete the Block Volume
To delete the block volume, run the following command.