Get 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.
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:
oci --help
oci bv volume -h
oci os bucket create -?
You can also view all the CLI help in your browser.
About the CLI Examples
The examples in this document are grouped as a command and a response, where:
- You are told what the command does, and given the command to use
- The result of the command is returned in a drop-down text box
The next example shows a command and response group.
To get the namespace for your tenancy, run the following command.
oci os ns get
Understanding Response Output
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:
{
"data": "docs"
"id": "ocid1.compartment.oc1..aaaaaaaal3gzijdhqol2pglie6astxxeyqdqeyg35nz5zxil2rggnx7jnhwa"
"is-stateless": null
}
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.
oci iam compartment list -c <tenancy_id>
oci iam compartment list -c ocid1.tenancy.oc1..aaaaaaaal1fvgn0h9njji5u6ldrwb4l6aay2x87qatw2wte30f714lal9oom
{
"data": [
{
"compartment-id": "ocid1.tenancy.oc1..aaaaaaaal1fvgn0h9njji5u6ldrwb4l6aay2x87qatw2wte30f714lal9oom",
"description": "For testing CLI features",
"id": "ocid1.tenancy.oc1..aaaaaaaal1fvgn0h9njji5u6ldrwb4l6aay2x87qatw2wte30f714lal9oom",
"inactive-status": null,
"lifecycle-state": "ACTIVE",
"name": "CLIsandbox",
"time-created": "2017-06-27T18:52:52.214000+00:00"
},
{
"compartment-id": "ocid1.tenancy.oc1..aaaaaaaal1fvgn0h9njji5u6ldrwb4l6aay2x87qatw2wte30f714lal9oom",
"description": "for testing",
"id": "ocid1.compartment.oc1..aaaaaaaasqn3hj6e5tq6slj4rpdqqja7qsyuqipmu4sv5ucmyp3rkmrhuv2q",
"inactive-status": null,
"lifecycle-state": "ACTIVE",
"name": "CLISandbox",
"time-created": "2017-05-12T21:31:27.709000+00:00"
}
],
"opc-next-page": " AAAAAAAAAAGLB28zJTjPUeNvgmLxg9QuJdAAZrl10FfKymIMh4ylXItQkO_Xk6RXbGxCn8hgkYm_pRpf1v6hVoxrYTQsaoveGMkX6iwwwPY5dptL8AKlyogYSs7F3G92KG2EhrI7j4NoUBtJ4-PTB53F2TZ31dReLsbzxBa3ljbwqQgwzQsUPYROLXA40EIJFdr2oYp67AzozSW8jt8MWFC8y19PsHEEEBW1jw8TT7Lq8XL_7mo5avasfsIYS7-VgP3ZFu6Y-Rab-gPNtjsT4pLh91BkDKWzbyHr0OmH4W1rhTJ5HfZ8YGpA0Ntm7_rOyNBd06qeBU496AQHk24-U_l9p4NvAvHuJ_fR-Z6ahgvWPlZQc1iCTRlJ6leM7ED3JNehIV0onOVQvGquJpF2WeEWFPcioQaqf4iScqHEchV--3Mn2k1yP_-b4AsVtSPRFYG8UuiRACPzg6ENVFjyeGOk3rrHjLR3j7s61pdgqtMOKZ1WtbOV8AcNON8ac1xJPN7O2YmjO3D0H4JmzXh_GxRskTpkl1D9En9zJXn99oWsNBOYgQQmv7s_7j82ZrXGoyOME-iT"
}
Create a Compartment
Help: oci iam compartment create -h
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.
oci iam compartment create --name <compartment_name> -c <root_compartment_id> --description "<friendly_description>"
oci iam compartment create --name CLIsandbox -c ocid1.tenancy.oc1..aaaaaaaal1fvgn0h9njji5u6ldrwb4l6aay2x87qatw2wte30f714lal9oom --description "For testing CLI features"
{
"data": {
"compartment-id": "ocid1.tenancy.oc1..aaaaaaaawuu4tdkysd2ups5fsclgm5ksfjwmx6mwem5sbjyw5ob5ojq2vkxa",
"description": "For testing CLI features",
"id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l",
"inactive-status": null,
"lifecycle-state": "ACTIVE",
"name": "CLIsandbox",
"time-created": "2017-06-27T18:52:52.214000+00:00"
},
"etag": "24a4737ede9d34eae934c93e9549ee684a15efc8"
}
"compartment-id": "ocid1.tenancy.oc1..aaaaaaaawuu4tdkysd2ups5fsclgm5ksfjwmx6mwem5sbjyw5ob5ojq2vkxa"
Creating a Virtual Cloud Network
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.
To create the VCN, run the following command.
oci network vcn create --compartment-id <compartment_id> --display-name "<friendly_name>" --dns-label <dns_name> --cidr-block "<0.0.0.0/0>"
Command Example and Responseoci network vcn create --compartment-id ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --display-name "cli_vcn" --dns-label sandboxvcn1 --cidr-block "10.0.0.0/16"
{ "data": { "cidr-block": "10.0.0.0/16", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "default-dhcp-options-id": "ocid1.dhcpoptions.oc1.phx.aaaaaaaaexnsdwsjmxnmmt4tpzkcbyengrnfpgnqzlkzz7qfx6faeqfbtcfa", "default-route-table-id": "ocid1.routetable.oc1.phx.aaaaaaaagdjre4rmk5dq6qqkftjtzyn7vctemqga3i6qrxvf23stedpujo2q", "default-security-list-id": "ocid1.securitylist.oc1.phx.aaaaaaaaxa3cr5zqshmed7zf64bxcrxb2zerinxhc52zrqe5w27hrau75j2q", "display-name": "cli_vcn", "dns-label": "sandboxvcn1", "id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr", "lifecycle-state": "AVAILABLE", "time-created": "2017-06-27T22:14:15.683000+00:00","vcn-domain-name": "sandboxvcn1.oraclevcn.com" }, "etag": "9037efc5" }
You can get information about any of your configurations by sending queries to your tenancy.
For example, to get network information, run the following command.
oci network vcn list -c <compartment_id>
Command Example and Responseoci network vcn list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l
{ "data": [ { "cidr-block": "10.0.0.0/16", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "default-dhcp-options-id": "ocid1.dhcpoptions.oc1.phx.aaaaaaaaexnsdjmxncbydrwrnfwspgnqzlkzz7qfmmt4tpzkx6faeqfbtcfa", "default-route-table-id": "ocid1.routetable.oc1.phx.aaaaaaaagdjre4jtzyn7vctmqga3i6qrxvf2rmk5dqdrwqkft3stedpujo2q", "default-security-list-id": "ocid1.securitylist.oc1.phx.aaaaaaaaxa3cr5zqsdrwxb2zerinxhc52zrqe5wmed74bxczf27hrau75j2q", "display-name": "cli_vcn", "dns-label": "sandboxvcn1", "id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr", "lifecycle-state": "AVAILABLE", "time-created": "2017-06-27T22:14:15.683000+00:00", "vcn-domain-name": "sandboxvcn1.oraclevcn.com" } ] }
-
Configure a Security List Ingress Rule
Help:
oci network security-list create -h
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.
oci network security-list create -c <compartment_id> --egress-security-rules "[{"destination": "<0.0.0.0/0>", "protocol": "<6>", "isStateless": <true>, "tcpOptions": {"destinationPortRange": <null>, "sourcePortRange": <null>}}]" --ingress-security-rules "[{"source": "<0.0.0.0/0>", "protocol": "<6>", "isStateless": <false>, "tcpOptions": {"destinationPortRange": {"max": <3389>, "min": <3389>}, "sourcePortRange": <null>}}]" --vcn-id <vcn_id> --display-name <rule_name>
Command Example and Responseoci network security-list create -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --egress-security-rules "[{"destination": "0.0.0.0/0", "protocol": "6", "isStateless": true, "tcpOptions": {"destinationPortRange": null, "sourcePortRange": null}}]" --ingress-security-rules "[{"source": "0.0.0.0/0", "protocol": "6", "isStateless": false, "tcpOptions": {"destinationPortRange": {"max": 3389, "min": 3389}, "sourcePortRange": null}}]" --vcn-id ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr --display-name port3389rule
{ "data": { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "port3389rule", "egress-security-rules": [ { "destination": "0.0.0.0/0", "icmp-options": null, "is-stateless": true, "protocol": "6", "tcp-options": { "destination-port-range": { "max": null, "min": null }, "source-port-range": null }, "udp-options": null } ], "id": "ocid1.securitylist.oc1.phx.aaaaaaaa7snx4jjfons6o2h33drwdh5hev6elir55hnrhi2ywqfnd5rcqk4q", "ingress-security-rules": [ { "icmp-options": null, "is-stateless": false, "protocol": "6", "source": "0.0.0.0/0", "tcp-options": { "destination-port-range": { "max": 3389, "min": 3389 }, "source-port-range": null }, "udp-options": null } ], "lifecycle-state": "AVAILABLE", "time-created": "2017-08-23T19:50:58.104000+00:00", "vcn-id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr" }, "etag": "d063779e" }
-
Create a Subnet
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.
oci iam availability-domain list -c <compartment_id>
Command Example and Responseoci iam availability-domain list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l
{ "data": [ { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "name": "EMIr:PHX-AD-1" }, { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "name": "EMIr:PHX-AD-2" }, { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "name": "EMIr:PHX-AD-3" } ] }
To create a subnet in AD-1, run the following command.
oci network subnet create --vcn-id <vcn_id> -c <compartment_id> --availability-domain "<availability_domain_name>" --display-name <display_name> --dns-label "<dns_label>" --cidr-block "<10.0.0.0/16>" --security-list-ids "["<default_security_list_id>","<new_security_list_id>"]"
Command Example and Responseoci network subnet create --vcn-id ocid1.vcn.oc1.phx.aaaaaaaah2ast7desae6ok3amu64wozj3kskox75awryr5j2nd7tkocplajq -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --availability-domain "EMIr:PHX-AD-1" --display-name CLISUB --dns-label "vminstances" --cidr-block "10.0.0.0/16" --security-list-ids "["ocid1.securitylist.oc1.phx.aaaaaaaaw7c62ybv4f5drwv2mup3f75aiquhbkbh4s676muq5t7j5tjckvlq","ocid1.securitylist.oc1.phx.aaaaaaaa7snx4jjfons6o2h33drwdh5hev6elir55hnrhi2ywqfnd5rcqk4q"]"
{ "data": { "availability-domain": "EMIr:PHX-AD-1", "cidr-block": "10.0.0.0/16", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "dhcp-options-id": "ocid1.dhcpoptions.oc1.phx.aaaaaaaaexnsdjmxnmmt4tpzkengrnfwspgnqzldrw7qfx6cbyfaeqfbtcfa", "display-name": "CLISUB", "dns-label": "vminstances", "id": "ocid1.subnet.oc1.phx.aaaaaaaahvx05fhw7p320cxmdrwo5wlf50egig9cmdzs1plb1xl6c5wvb5s2", "lifecycle-state": "PROVISIONING", "prohibit-public-ip-on-vnic": false, "route-table-id": "ocid1.routetable.oc1.phx.aaaaaaaagdjqga3i6qrxvf23stedpre4rmkdrw6qeqkftjtzyn7vctmujo2q", "security-list-ids": [ "ocid1.securitylist.oc1.phx.aaaaaaaaw7c62ybv4f5drwv2mup3f75aiquhbkbh4s676muq5t7j5tjckvlq", "ocid1.securitylist.oc1.phx.aaaaaaaa7snx4jjfons6o2h33drwdh5hev6elir55hnrhi2ywqfnd5rcqk4q" ], "subnet-domain-name": vminstances.sandboxvcn1.oraclevcn.com, "time-created": "2017-08-24T00:51:30.462000+00:00", "vcn-id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr", "virtual-router-ip": "10.0.0.1", "virtual-router-mac": "00:00:17:7F:8A:D7" }, "etag": "92d20c35" }
-
Create an Internet Gateway
Help:
oci network internet-gateway create -h
To create an Internet Gateway, run the following command.
oci network internet-gateway create -c <compartment_id> --is-enabled <true> --vcn-id <vcn_id> --display-name <gateway_display_name>
Command Example and Responseoci network internet-gateway create -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --is-enabled true --vcn-id ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr --display-name sbgateway
{ "data": { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "sbgateway", "id": "ocid1.internetgateway.oc1.phx.aaaaaaaa3vcd7gmqqh4po6wnsjhcdkxlddeqinmnbanzz2wsh5gdrwt574ka", "is-enabled": true, "lifecycle-state": "AVAILABLE", "time-created": "2017-08-25T20:03:48.482000+00:00", "vcn-id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr" }, "etag": "d13fb7e3" }
-
Add a Rule to the Route Table
Help:
oci network route-table list -h
,oci network route-table update -h
When you create a VCN, a route table is created automatically. Before you add a rule to the route table, you need the OCID for the table.
To get the route table OCID, run the following command.
oci network route-table list -c <compartment_id> --vcn-id <vcn_id>
Command Example and Responseoci network route-table list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --vcn-id ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr
{ "data": [ { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Default Route Table for cli_vcn", "id": "ocid1.routetable.oc1.phx.aaaaaaaagdjqga3i6qrxvf23stedpre4rmkdrw6qeqkftjtzyn7vctmujo2q", "lifecycle-state": "AVAILABLE", "route-rules": [], "time-created": "2017-08-25T21:46:04.324000+00:00", "vcn-id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr" } ] }
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.
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
Command Example and Responseoci 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
{ "data": { "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Default Route Table for cli_vcn", "id": "ocid1.routetable.oc1.phx.aaaaaaaa4kujevzdsnd7bh6aetvrhvzdrwcxmmblspmyj3pqwckchajvz6fa", "lifecycle-state": "AVAILABLE", "route-rules": [ { "cidr-block": "0.0.0.0/0", "network-entity-id": "ocid1.internetgateway.oc1.phx.aaaaaaaa3vcd7gmqqh4po6wnsjhcdkxlddeqinmnbanzz2wsh5gdrwt574ka" } ], "time-created": "2017-08-25T23:46:04.324000+00:00","vcn-id": "ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr" }, "etag": "3fc998d8" }
Preparing to Launch an Instance
When you launch an instance you have to provide the following information, some of which you've already obtained:
compartment-id
availability-domain
subnet-id
image-id
shape
-
Get Information About the Available Images
Help:
oci compute image list -h
The
image-id
identifies the operating system that you want to install. For more information, see Platform Images.To get a list of images, run the following command.
oci compute image list -c <compartment_id>
Command Example and ResponseImages are available for: Oracle Linux, CentOS, Ubuntu, and Windows Server. This response example only shows the information for Oracle Linux 7.3.
oci compute image list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l
{ "base-image-id": null, "compartment-id": null, "create-image-allowed": true, "display-name": "Oracle-Linux-7.3-2017.03.03-0", "id": "ocid1.image.oc1.phx.aaaaaaaaevkccomzepja4yhahz6rguhqbuomuto7gdrw5hjimqsig6syeqda", "lifecycle-state": "AVAILABLE", "operating-system": "Oracle Linux", "operating-system-version": "7.3", "time-created": "2017-03-03T19:04:30.824000+00:00" }
-
Get Information About the Available Shapes
Help:
oci compute shape list -h
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.
oci compute shape list -c <compartment_id> --availability-domain "<availability_domain_name>"
Command Example and Responseoci compute shape list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --availability-domain "EMIr:PHX-AD-1"
{ "data": [ { "shape": "BM.Standard1.36" }, { "shape": "VM.Standard1.1" }, { "shape": "VM.Standard1.2" }, { "shape": "VM.Standard1.4" }, { "shape": "VM.Standard1.8" }, { "shape": "VM.Standard1.16" }, { "shape": "VM.DenseIO1.4" } ] }
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
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.
oci compute instance launch --availability-domain "<availability_domain_name>" -c <compartment_id> --shape "<shape_name>" --display-name "<instance_display_name>" --image-id <image_id> --ssh-authorized-keys-file "<path_to_authorized_keys_file>" --subnet-id <subnet_id>
Command Example and Responseoci compute instance launch --availability-domain "EMIr:PHX-AD-1" -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --shape "VM.Standard1.1" --display-name "Linux Instance" --image-id ocid1.image.oc1.phx.aaaaaaaa5yu6pw3riqtuhxzov7fdngi4tsteganmao54nq3pyxu3hxcuzmoa --ssh-authorized-keys-file "C:\Users\testuser\.oci\linux_key.pem" --subnet-id ocid1.subnet.oc1.phx.aaaaaaaahvx05fhw7p320cxmdrwo5wlf50egig9cmdzs1plb1xl6c5wvb5s2
{ "data": { "availability-domain": "EMIr:PHX-AD-1", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Linux Instance", "extended-metadata": {}, "id": "ocid1.instance.oc1.phx.abyhqljrtv7hhenrra6hsdrwjqvszcr2gs7c76tuuzc33iyl6bz5mfnbzw7q", "image-id": "ocid1.image.oc1.phx.aaaaaaaa5yu6pw3riqtuhxzov7fdngi4tsteganmao54nq3pyxu3hxcuzmoa", "ipxe-script": null, "lifecycle-state": "RUNNING", "metadata": { "ssh_authorized_keys": "ssh-rsa AAAAB3NzaABJQAAAQC1yc2EAAAEAtaT/s9HZ24VeLUxcBNT//nPygk75BWpA+kuQotpH4yP1tpqJvOBZoTKwoYa0BuoVcY4VP1GkuCEUrpojZ5F6LybbVeO+ixpuxcPTRNZcVPZJfUVZqg7u8CCjih2T9qH9ZrOcXBJCyKrxEE2kkP4RunnS38MvuDnySYus/04V8l7sEudqWWQX88iZO4oV+Sc4vljbZIaOqNrlAJV5xfQHISL2Ejq8Q1JKaO2Mc6D4Ku/6qEwe0ihtPGoi0zFmPoWstfgc1UqTdiRsYECzzaWqVYpl7RO5h4pIP6/lgBfOsv/Dcg19ND7/qKnmJ4/9iKuacI2bm+HF2oR0gY4C2MvL3Q== rsa-key-20817080\n" }, "region": "phx", "shape": "VM.Standard1.1", "time-created": "2017-08-26T20:39:03.340000+00:00" }, "etag": "2df9d1f14856a2e9a0cc239417f1ee829288b8badeb7ac6fb6d5b3553cbd148c--gzip" }
-
Get VNIC Information for the Instance
Help:
oci compute instance list-vnics -h
You need the public IP address of the instance in order to connect to the instance. The VNIC for the instance has this information.
To get a list of VNICs for the instance, run the following command.
oci compute instance list-vnics --instance-id <instance_id>
Command Example and Responseoci compute instance list-vnics --instance-id ocid1.instance.oc1.phx.abcdefgh6kykdowc8ozzvr4421kwp7apdrwk6wrjl7su82d60c6sp4nap88d
{ "data": [ { "availability-domain": "EMIr:PHX-AD-1", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Linux Instance", "hostname-label": null, "id": "ocid1.vnic.oc1.phx.abyhqljrxqrdrwuhj4nly7dp7ctr7xvclvejc7pu5rq77e37vlsq2al5y74a", "lifecycle-state": "AVAILABLE", "private-ip": "10.0.0.2", "public-ip": "129.145.32.236", "subnet-id": "ocid1.subnet.oc1.phx.aaaaaaaahvx05fhw7p320cxmdrwo5wlf50egig9cmdzs1plb1xl6c5wvb5s2", "time-created": "2017-08-24T00:51:30.462000+00:00" } [ }
-
Create a Block Volume for the Instance
Help:
oci bv volume create -h
Create a block volume, using the minimum available size.
Caution
Block volume sizes are expressed as increments of 1024 MB. The next command example uses the minimum size,
--size-in-mbs 51200
, or 50 GB.To create a block volume, run the following command.
oci bv volume create --availability-domain "<availability_domain_name>" -c <compartment_id> --size-in-mbs <51200> --display-name <volume_display_name>
Command Example and Responseoci bv volume create --availability-domain "EMIr:PHX-AD-1" -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --size-in-mbs 51200 --display-name LinuxVol
{ "data": { "availability-domain": "EMIr:PHX-AD-1", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "LinuxVol", "id": "ocid1.volume.oc1.phx.abyhqlsktp2ec7pdazl4y324drw5lxruh5nxjrgbgqq7znsj5oo4t25nvcta", "lifecycle-state": "PROVISIONING", "size-in-mbs": 51200, "time-created": "2017-08-26T00:51:30.462000+00:00" }, "etag": "720652578" }
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.
oci compute volume-attachment attach --instance-id <instance_id> --type <iscsi> --volume-id <volume_id>
Command Example and Responseoci compute volume-attachment attach --instance-id ocid1.instance.oc1.phx.abcdefgh6kykdowc8ozzvr4421kwp7apdrwk6wrjl7su82d60c6sp4nap88d --type iscsi --volume-id ocid1.volume.oc1.phx.abyhqljrgbktp2ec7pdazl4y324drw5lxruh5nxt25gqq7znsj5oo4snvcta
{ "data": { "attachment-type": "iscsi", "availability-domain": "EMIr:PHX-AD-1", "chap-secret": null, "chap-username": null, "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": null, "id": "ocid1.volumeattachment.oc1.phx.abyhqlytoivg6eaybdrwb7mqqms6utjrefofrplyip7filf3vtpk55h2hzlq", "instance-id": "ocid1.instance.oc1.phx.abcdefgh6kykdowc8ozzvr4421kwp7apdrwk6wrjl7su82d60c6sp4nap88d", "ipv4": null, "iqn": null, "lifecycle-state": "ATTACHING", "port": null, "time-created": "2017-08-26T00:55:30.462000+00:00", "volume-id": "ocid1.volume.oc1.phx.fewtr0p6pm9lj7h7rpf8w3drwlf4x9tadrw1sbs7n5qkx7dcu7bk" }, "etag": "0c0afdb14a0a10ffc15283366798ac82f623433e6f5619eb2d4469612b32a332" }
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.
-
Launch the Instance
Help:
oci compute instance launch -h
To launch the Windows instance, run the following command.
oci compute instance launch --availability-domain "<availability_domain_name>" -c <compartment_id> --shape "<shape_name>" --display-name "<instance_display_name>" --image-id <image_id> --subnet-id <subnet_id>
Command Example and Responseoci compute instance launch --availability-domain "EMIr:PHX-AD-1" -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l --shape "VM.Standard1.2" --display-name "Windows Instance" --image-id ocid1.image.oc1.phx.aaaaaaaa53cliasgvqmueus5byytfldrwafbro2y4ywjebci5szc42e2b7ua --subnet-id ocid1.subnet.oc1.phx.aaaaaaaaypsr25bzjmj3drwiha6lodzus3yn6xwgkcrgxdgafscirbhj5bpa
{ "data": { "availability-domain": "EMIr:PHX-AD-1", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Windows Instance", "extended-metadata": {}, "id": "ocid1.instance.oc1.phx.zsutzirph7cbrbx6rzu91stavdrw58puq3isknlr07zfcd6rq6p9", "image-id": "ocid1.image.oc1.phx.aaaaaaaa53cliaskafbro2y4drwebci5szc4eus5bygvqmutflwqy2e2b7ua", "ipxe-script": null, "lifecycle-state": "PROVISIONING", "metadata": {}, "region": "phx", "shape": "VM.Standard1.2", "time-created": "2017-08-26T00:51:30.462000+00:00" }, "etag": "4ec3da1e2415c49f55ed705c4d81edb2739da62946d36d73f816e8241e705b3b" }
-
Get VNIC Information for the Instance
To get the VNIC information, run the following command.
oci compute instance list-vnics --instance-id <instance_id>
-
Create a Block Volume for the Instance
To create a block volume, run the following command.
oci bv volume create --availability-domain "<availability_domain_name>" -c <compartment_id> --size-in-mbs <51200> --display-name <display_name>
-
Attach the Block Volume to the Instance
To attach the Block Volume to the Windows instance, run the following command.
oci compute volume-attachment attach --instance-id <instance_id> --type <iscsi> --volume-id <volume_id>
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.
-
Connect to Your Linux Instance
Connecting to Your Instance describes how to connect to a Linux instance from a Unix-style or Windows-style system.
-
Connect to Your Windows Instance
Help:
oci compute instance list-vnics -h
andoci compute instance get-windows-initial-creds -h
To connect to the instance using Remote Desktop Client (RDC), you need:
- The public IP address for the instance
- The initial Windows credentials
To get the public IP address of the Windows instance, run the following command.
oci compute instance list-vnics --instance-id <instance_id>
Command Example and Responseoci compute instance list-vnics --instance-id ocid1.instance.oc1.phx.zsutzirph7cbrbx6rzu91stavdrw58puq3isknlr07zfcd6rq6p9
{ "data": [ { "availability-domain": "EMIr:PHX-AD-1", "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": "Windows Instance", "hostname-label": null, "id": "ocid1.vnic.oc1.phx.abyhqljr5m5mmra3ecxasw6vdrwq5ft23dqn4dlrl45hdggz6rgfdwpp4ija", "lifecycle-state": "AVAILABLE", "private-ip": "10.10.0.3", "public-ip": "129.142.0.212", "subnet-id": "ocid1.subnet.oc1.phx.aaaaaaaahvx05fhw7p320cxmdrwo5wlf50egig9cmdzs1plb1xl6c5wvb5s2", "time-created": "2017-08-26T00:51:30.462000+00:00" } ] }
To get the initial Windows credentials, run the following command.
oci compute instance get-windows-initial-creds --instance-id <instance_id>
Command Example and Responseoci compute instance get-windows-initial-creds --instance-id ocid1.instance.oc1.phx.zsutzirph7cbrbx6rzu91stavdrw58puq3isknlr07zfcd6rq6p9
{ "data": { "password": "Cz{73~~vf@dnK7A", "username": "opc" } }
Connecting to Your Windows Instance describes how to connect to your instance using RDC.
Cleaning Up the Test Environment
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.
oci compute volume-attachment list -c <compartment_id>
Command Example and Responseoci compute volume-attachment list -c ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l
{ "data": [ { "attachment-type": "iscsi", "availability-domain": "EMIr:PHX-AD-1", "chap-secret": null, "chap-username": null, "compartment-id": "ocid1.compartment.oc1..aaaaaaaalkqnr7pfd92rdrwo5fm6fcoufoih1vd4ls4j9jjpge16vfyxrc1l", "display-name": null, "id": "ocid1.volumeattachment.oc1.phx.abyhqlytoivg6eaybdrwb7mqqms6utjrefofrplyip7filf3vtpk55h2hzlq", "instance-id": "ocid1.instance.oc1.phx.abcdefgh6kykdowc8ozzvr4421kwp7apdrwk6wrjl7su82d60c6sp4nap88d", "ipv4": "169.254.2.2", "iqn": "iqn.2015-12.com.oracleiaas:e3fd73db-b164-4d76-bc3f-f58b093989d0", "lifecycle-state": "ATTACHED", "port": 3260, "time-created": "2017-08-26T00:51:30.462000+00:00", "volume-id": "ocid1.volume.oc1.phx.abyhqpa3ati7ggfjvba7y6dcg7imdrwskq4bdljroo2cbwchrebuprxddvca" } ] } }
-
Detach the
volume-attachment-id
To detach the volume attachment-id, run the following command.
oci compute volume-attachment detach --volume-attachment-id <volume_attachment_id>
Command Example and Responseoci compute volume-attachment detach --volume-attachment-id ocid1.volumeattachment.oc1.phx.abyhqlytoivg6eaybdrwb7mqqms6utjrefofrplyip7filf3vtpk55h2hzlq
All destructive actions, such as detaching and deleting resources allow you to use theAre you sure you want to delete this resource? [y/N]:
--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.
oci bv volume delete --volume-id <volume_id> --force
Command Example and Response-
oci bv volume delete --volume-id ocid1.volume.oc1.phx.abyhqljroo2cbwchrpa3ati7ggfjvba7y6dcg7imnleskq4bdebuprxddvca --force
There is no response to this action. To verify that the block volume was deleted, run the following command.
oci bv volume list -c <compartment_id>
The response to this query returns
"lifecycle-state": "TERMINATED"
, showing that the volume doesn't exist.
-
To delete the block volume attached to the Windows instance, use the preceding steps (1-3) as a guide.
Terminate the Instances
Help: oci compute instance terminate -h
To delete the Linux instance, run the following command.
oci compute instance terminate --instance-id <instance_id>
oci compute instance terminate --instance-id ocid1.instance.oc1.phx.abcdefgh6kykdowc8ozzvr4421kwp7apdrwk6wrjl7su82d60c6sp4nap88d
Are you sure you want to delete this resource? [y/N]:
Confirm the deletion. No response is returned after the instance is deleted.
To delete the Windows instance, run the following command.
oci compute instance terminate --instance-id <instance_id>
oci compute instance terminate --instance-id ocid1.instance.oc1.phx.zsutzirph7cbrbx6rzu91stavdrw58puq3isknlr07zfcd6rq6p9
Are you sure you want to delete this resource? [y/N]:
Confirm the deletion. No response is returned after the instance is deleted.
Delete the Virtual Cloud Network
Help: oci network subnet delete -h
, oci network vcn delete -h
It takes the following 2 steps to delete the VCN.
-
Delete the subnet
To delete the subnet, run the following command.
oci network subnet delete --subnet-id <subnet_id> --force
Command Example and Responseoci network subnet delete --subnet-id ocid1.subnet.oc1.phx.aaaaaaaahvx05fhw7p320cxmdrwo5wlf50egig9cmdzs1plb1xl6c5wvb5s2 --force
None
- Delete the virtual cloud network
To delete the VCN, run the following command.
oci network vcn delete --vcn-id <vcn_id> --force
Command Example and Responseoci network vcn delete --vcn-id ocid1.vcn.oc1.phx.aaaaaaaa6va8fxr1m4hvzjk3nzo8x290qymdrwiblxw5qpzlm64rdd74vchr --force
None