이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 4. Developer CLI Operations


4.1. Overview

This topic provides information on the developer CLI operations and their syntax. You must setup and login with the CLI before you can perform these operations.

The developer CLI uses the oc command, and is used for project-level operations. This differs from the administrator CLI, which uses the oadm command for more advanced, administrator operations.

4.2. Common Operations

The developer CLI allows interaction with the various objects that are managed by OpenShift Enterprise. Many common oc operations are invoked using the following syntax:

$ oc <action> <object_type> <object_name>
Copy to Clipboard Toggle word wrap

This specifies:

  • An <action> to perform, such as get or describe.
  • The <object_type> to perform the action on, such as service or the abbreviated svc.
  • The <object_name> of the specified <object_type>.

For example, the oc get operation returns a complete list of services that are currently defined:

$ oc get svc
NAME              LABELS                                    SELECTOR                  IP              PORT(S)
docker-registry   docker-registry=default                   docker-registry=default   172.30.78.158   5000/TCP
kubernetes        component=apiserver,provider=kubernetes   <none>                    172.30.0.2      443/TCP
kubernetes-ro     component=apiserver,provider=kubernetes   <none>                    172.30.0.1      80/TCP
Copy to Clipboard Toggle word wrap

The oc describe operation can then be used to return detailed information about a specific object:

$ oc describe svc docker-registry
Name:			docker-registry
Labels:			docker-registry=default
Selector:		docker-registry=default
IP:			172.30.78.158
Port:			<unnamed>	5000/TCP
Endpoints:		10.1.0.2:5000
Session Affinity:	None
No events.
Copy to Clipboard Toggle word wrap
Warning

Versions of oc prior to 3.0.2.0 did not have the ability to negotiate API versions against a server. So if you are using oc up to 3.0.1.0 with a server that only supports v1 or higher versions of the API, make sure to pass --api-version in order to point the oc client to the correct API endpoint. For example: oc get svc --api-version=v1.

4.3. Object Types

The CLI supports the following object types, some of which have abbreviated syntax:

Expand
Object TypeAbbreviated Version

build

 

buildConfig

bc

deploymentConfig

dc

event

ev

imageStream

is

imageStreamTag

istag

imageStreamImage

isimage

job

 

LimitRange

limits

node

 

pod

po

ResourceQuota

quota

replicationController

rc

secrets

 

service

svc

ServiceAccount

serviceaccounts

persistentVolume

pv

persistentVolumeClaim

pvc

4.4. Basic CLI Operations

The following table describes basic oc operations and their general syntax:

4.4.1. types

Display an introduction to some core OpenShift Enterprise concepts:

$ oc types
Copy to Clipboard Toggle word wrap

4.4.2. login

Log in to the OpenShift Enterprise server:

$ oc login
Copy to Clipboard Toggle word wrap

4.4.3. logout

End the current session:

$ oc logout
Copy to Clipboard Toggle word wrap

4.4.4. new-project

Create a new project:

$ oc new-project <project_name>
Copy to Clipboard Toggle word wrap

4.4.5. new-app

Creates a new application based on the source code in the current directory:

$ oc new-app .
Copy to Clipboard Toggle word wrap

4.4.6. status

Show an overview of the current project:

$ oc status
Copy to Clipboard Toggle word wrap

4.4.7. project

Switch to another project. Run without options to display the current project. To view all projects you have access to run oc projects. Run without options to display the current project. To view all projects you have access to run oc projects.

$ oc project <project_name>
Copy to Clipboard Toggle word wrap

4.5. Application Modification CLI Operations

4.5.1. get

Return a list of objects for the specified object type. If the optional <object_name> is included in the request, then the list of results is filtered by that value.

$ oc get <object_type> [<object_name>]
Copy to Clipboard Toggle word wrap

4.5.2. describe

Returns information about the specific object returned by the query. A specific <object_name> must be provided. The actual information that is available varies as described in object type.

$ oc describe <object_type> <object_name>
Copy to Clipboard Toggle word wrap

4.5.3. edit

Edit the desired object type:

$ oc edit <object_type>/<object_name>
Copy to Clipboard Toggle word wrap

Edit the desired object type with a specified text editor:

$ OC_EDITOR="<text_editor>" oc edit <object_type>/<object_name>
Copy to Clipboard Toggle word wrap

Edit the desired object in a specified format (eg: JSON):

$ oc edit <object_type>/<object_name> \
    --output-version=<object_type_version> \
    -o <object_type_format>
Copy to Clipboard Toggle word wrap

4.5.4. env

Update the desired object type with a new environment variable:

$ oc env <object_type>/<object_name> <var_name>=<value>
Copy to Clipboard Toggle word wrap

4.5.5. volume

Modify a volume:

$ oc volume <object_type>/<object_name> [--option]
Copy to Clipboard Toggle word wrap

4.5.6. label

Update the labels on a object:

$ oc label <object_type> <object_name> <label>
Copy to Clipboard Toggle word wrap

4.5.7. expose

Look up a service and expose it as a route. There is also the ability to expose a deployment configuration, replication controller, service, or pod as a new service on a specified port. If no labels are specified, the new object will re-use the labels from the object it exposes.

$ oc expose <object_type> <object_name>
Copy to Clipboard Toggle word wrap

4.5.8. delete

Delete the specified object. An object configuration can also be passed in through STDIN. The oc delete all -l <label> operation deletes all objects matching the specified <label>, including the replication controller so that pods are not re-created.

$ oc delete -f <file_path>
Copy to Clipboard Toggle word wrap
$ oc delete <object_type> <object_name>
Copy to Clipboard Toggle word wrap
$ oc delete <object_type> -l <label>
Copy to Clipboard Toggle word wrap
$ oc delete all -l <label>
Copy to Clipboard Toggle word wrap

4.6. Build and Deployment CLI Operations

One of the fundamental capabilities of OpenShift Enterprise is the ability to build applications into a container from source.

OpenShift Enterprise provides CLI access to inspect and manipulate deployment configurations using standard oc resource operations, such as get, create, and describe.

4.6.1. start-build

Manually start the build process with the specified build configuration file:

$ oc start-build <buildconfig_name>
Copy to Clipboard Toggle word wrap

Manually start the build process by specifying the name of a previous build as a starting point:

$ oc start-build --from-build=<build_name>
Copy to Clipboard Toggle word wrap

Manually start the build process by specifying either a configuration file or the name of a previous build and retrieve its build logs:

$ oc start-build --from-build=<build_name> --follow
Copy to Clipboard Toggle word wrap
$ oc start-build <buildconfig_name> --follow
Copy to Clipboard Toggle word wrap

Wait for a build to complete and exit with a non-zero return code if the build fails:

$ oc start-build --from-build=<build_name> --wait
Copy to Clipboard Toggle word wrap

Set or override environment variables for the current build without changing the build configuration. Alternatively, use -e.

$ oc start-build --env <var_name>=<value>
Copy to Clipboard Toggle word wrap

Set or override the default build log level output during the build:

$ oc start-build --build-loglevel [0-5]
Copy to Clipboard Toggle word wrap

Specify the source code commit identifier the build should use; requires a build based on a Git repository:

$ oc start-build --commit=<hash>
Copy to Clipboard Toggle word wrap

Re-run build with name <build_name>:

$ oc start-build --from-build=<build_name>
Copy to Clipboard Toggle word wrap

Archive <dir_name> and build with it as the binary input:

$ oc start-build --from-dir=<dir_name>
Copy to Clipboard Toggle word wrap

Use <file_name> as the binary input for the build. This file must be the only one in the build source. For example, pom.xml or Dockerfile.

$ oc start-build --from-file=<file_name>
Copy to Clipboard Toggle word wrap

The path to a local source code repository to use as the binary input for a build:

$ oc start-build --from-repo=<path_to_repo>
Copy to Clipboard Toggle word wrap

Specify a webhook URL for an existing build configuration to trigger:

$ oc start-build --from-webhook=<webhook_URL>
Copy to Clipboard Toggle word wrap

The contents of the post-receive hook to trigger a build:

$ oc start-build --git-post-receive=<contents>
Copy to Clipboard Toggle word wrap

The path to the Git repository for post-receive; defaults to the current directory:

$ oc start-build --git-repository=<path_to_repo>
Copy to Clipboard Toggle word wrap

List the webhooks for the specified build configuration or build; accepts all, generic, or github:

$ oc start-build --list-webhooks
Copy to Clipboard Toggle word wrap

4.6.2. deploy

View a deployment, or manually start, cancel, or retry a deployment:

$ oc deploy <deploymentconfig>
Copy to Clipboard Toggle word wrap

4.6.3. rollback

Perform a rollback:

$ oc rollback <deployment_name>
Copy to Clipboard Toggle word wrap

4.6.4. new-build

Create a build configuration based on the source code in the current Git repository (with a public remote) and a Docker image:

$ oc new-build .
Copy to Clipboard Toggle word wrap

4.6.5. cancel-build

Stop a build that is in progress:

$ oc cancel-build <build_name>
Copy to Clipboard Toggle word wrap

4.6.6. import-image

Import tag and image information from an external Docker image repository:

$ oc import-image <imagestream>
Copy to Clipboard Toggle word wrap

4.6.7. scale

Set the number of desired replicas for a replication controller or a deployment configuration to the number of specified replicas:

$ oc scale <object_type> <object_name> --replicas=<#_of_replicas>
Copy to Clipboard Toggle word wrap

4.6.8. tag

Take an existing tag or image from an image stream, or a Docker image pull spec, and set it as the most recent image for a tag in one or more other image streams:

$ oc tag <current_image> <image_stream>
Copy to Clipboard Toggle word wrap

4.7. Advanced Commands

4.7.1. create

Parse a configuration file and create one or more OpenShift Enterprise objects based on the file contents. The -f flag can be passed multiple times with different file or directory paths. When the flag is passed multiple times, oc create iterates through each one, creating the objects described in all of the indicated files. Any existing resources are ignored.

$ oc create -f <file_or_dir_path>
Copy to Clipboard Toggle word wrap

4.7.2. update

Attempt to modify an existing object based on the contents of the specified configuration file. The -f flag can be passed multiple times with different file or directory paths. When the flag is passed multiple times, oc update iterates through each one, updating the objects described in all of the indicated files.

$ oc update -f <file_or_dir_path>
Copy to Clipboard Toggle word wrap

4.7.3. process

Transform a project template into a project configuration file:

$ oc process -f <template_file_path>
Copy to Clipboard Toggle word wrap

4.7.4. run

Create and run a particular image, possibly replicated. Create a deployment configuration to manage the created container(s). You can choose to run in the foreground for an interactive container execution.

$ oc run NAME --image=<image> \
    [--port=<port>] \
    [--replicas=<replicas>] \
    [--dry-run=<bool>] \
    [--overrides=<inline-json>] \
    [options]
Copy to Clipboard Toggle word wrap

4.7.5. export

Export resources to be used elsewhere:

$ oc export <object_type> [--options]
Copy to Clipboard Toggle word wrap

4.7.6. policy

Manage authorization policies:

$ oc policy [--options]
Copy to Clipboard Toggle word wrap

4.7.7. secrets

Configure secrets:

$ oc secrets [--options] path/to/ssh_key
Copy to Clipboard Toggle word wrap

4.8. Troubleshooting and Debugging CLI Operations

4.8.1. logs

Retrieve the log output for a specific build, deployment, or pod. This command works for builds, build configurations, deployment configurations, and pods.

$ oc logs -f <pod>
Copy to Clipboard Toggle word wrap

4.8.2. exec

Execute a command in an already-running container. You can optionally specify a container ID, otherwise it defaults to the first container.

$ oc exec <pod> [-c <container>] <command>
Copy to Clipboard Toggle word wrap

4.8.3. rsh

Open a remote shell session to a container:

$ oc rsh <pod>
Copy to Clipboard Toggle word wrap

4.8.4. rsync

Copy contents of local directory to a directory in an already-running pod container. It will default to the first container if none is specified.

$ oc rsync <local_dir> <pod>:<pod_dir> -c <container>
Copy to Clipboard Toggle word wrap

4.8.5. port-forward

Forward one or more local ports to a pod:

$ oc port-forward <pod> <local_port>:<remote_port>
Copy to Clipboard Toggle word wrap

4.8.6. proxy

Run a proxy to the Kubernetes API server:

$ oc proxy --port=<port> --www=<static_directory>
Copy to Clipboard Toggle word wrap
Important

For security purposes, the oc exec command does not work when accessing privileged containers. Instead, administrators can SSH into a node host, then use the docker exec command on the desired container.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat