Getting Started with the Command Line Interface

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.

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:

Before You Begin

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.

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.

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.

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.

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".

Launching a Linux Instance

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

Warning

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.

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

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.

Connecting to Your Instances

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.

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.