Getting started with the cf CLI | Cloud Foundry Docs (2024)

  • Prerequisite
  • Log in with the CLI
  • Log in with the API
  • Localize the cf CLI
  • Manage users and roles
    • List users
    • Manage roles
    • Manage roles for users with identical usernames in multiple origins
  • Push an app
    • Push a new app or push changes to an app
    • Push an app using a manifest
    • Push an app with a buildpack
    • Map a route to an app
  • Manage user-provided service instances
    • Create a service instance
    • Bind and unbind service instances
    • Update a service instance
  • Retrieve cf CLI return codes
  • View CLI help output

Page last updated:

The cf CLI is the official command line client for Cloud Foundry. You can use the cf CLI to manage apps, service instances, orgs, spaces, and users in your environment.

Prerequisite

To follow the procedures in this topic, you must download and install the latest version of the cf CLI v7 or v8. For more information, see Installing the Cloud Foundry command line interface.

Log in with the CLI

The cf login command uses the syntax described below to specify a target API endpoint, login credentials, an org, and a space.

The cf CLI prompts for credentials as needed. If you are a member of multiple orgs or spaces, cf login prompts you to specify the org or space to which youwant to log in. Otherwise, it targets your org and space automatically.

To log in to the cf CLI:

  1. In a terminal window, run:

    cf login -a API-URL -u USERNAME -p PASSWORD -o ORG -s SPACE

    Where:

    • API-URL is your API endpoint, the URL of the Cloud Controller in your Cloud Foundry instance.
    • USERNAME is your username.
    • PASSWORD is your password. Cloud Foundry discourages using the -p option, because it records your password in your shell history.
    • ORG is the org where you want to deploy your apps.
    • SPACE is the space in the org where you want to deploy your apps.

When you successfully log in, you see output similar to the following example:

API endpoint: https://api.example.comPassword>Authenticating...OKTargeted org example-orgTargeted space developmentAPI endpoint: https://api.example.comUser: username@example.comOrg: example-orgSpace: development

Alternatively, you can write a script to log in and set your target using the non-interactive cf api, cf auth, and cf target commands. See UAAC for setting up client_id and client_secret.

Log in with the API

You can write a script to log in to the cf CLI. This allows you to avoid manually logging in to the cf CLI each time you use it.

To write a script to log in:

  1. In a terminal window, target your API by running:

    cf api API-URL

    Where API-URL is your API endpoint, the URL of the Cloud Controller in your Cloud Foundry instance.

    For more information about the cf api command, see the Cloud Foundry CLI Reference Guide.

  2. Authenticate by running:

    cf auth USERNAME PASSWORD

    Where:

    • USERNAME is your username.
    • PASSWORD is your password. Cloud Foundry discourages using the -p option, because it records your password in your shell history.

    For more information about the cf auth command, see the Cloud Foundry CLI Reference Guide.

  3. Target your org or space by running:

    cf target -o ORG -s SPACE

    Where:

    • ORG is the org you want to target.
    • SPACE is the space you want to target.

    For more information about the cf target command, see the Cloud Foundry CLI Reference Guide.

After you log in, the cf CLI saves a config.json file that contains your API endpoint, org, space values, and access token. If you change these settings,the config.json file is updated accordingly.

By default, config.json is located in the ~/.cf directory. You can relocate the config.json file using the CF_HOME environment variable.

Localize the cf CLI

The cf CLI translates terminal output into the language that you select. The default language is en-US.

The cf CLI supports these languages:

  • Chinese (simplified): zh-Hans
  • Chinese (traditional): zh-Hant
  • English: en-US
  • French: fr-FR
  • German: de-DE
  • Italian: it-IT
  • Japanese: ja-JP
  • Korean: ko-KR
  • Portuguese (Brazil): pt-BR
  • Spanish: es-ES

For more information about the cf config --locale command, see the Cloud Foundry CLI Reference Guide.

Localizing the cf CLI affects only messages that the cf CLI generates.

To set the language of the cf CLI:

  1. In a terminal window, log in to the cf CLI:

    cf login
  2. Run:

    cf config --locale LANGUAGE

    Where LANGUAGE is code of the language you want to set. Valid values are zh-Hans, zh-Hant, en-US, fr-FR, de-DE, it-IT, ja-JP, ko-KR,pt-BR, and es-ES.

  3. Confirm the language change by running:

    cf help

    The above command returns output similar to the example below:

    NOME: cf - Uma ferramenta de linha de comando para interagir com Cloud Foundry

    USO: cf [opções globais] comando [argumentos...] [opções de comando]

    VERSÃO: 6.14.1 ...

Manage users and roles

The cf CLI includes commands that list users and assign roles in orgs and spaces.

List users

To list all users in an org or a space:

  1. In a terminal window, log in to the cf CLI:

    cf login
  2. Run one of these commands:

    • To list org users, run:

      cf org-users ORG

      Where ORG is the name of the org for which you want to see the list of users.

      The above command returns output similar to the example below:

      Getting users in org example-org as username@example.com...

      ORG MANAGER username@example.com

      BILLING MANAGER huey@example.com dewey@example.com

      ORG AUDITOR louie@example.com

    • To list space users, run:

      cf space-users ORG SPACE

      Where:

      • ORG is the name of the org that contains the space for which you want to see the list of users.
      • SPACE is the name of the space for which you want to see the list of users.

      The above command returns output similar to the example below:

      Getting users in org example-org / space example-space as username@example.com...

      SPACE MANAGER username@example.com

      SPACE DEVELOPER huey@example.com dewey@example.com

      SPACE AUDITOR louie@example.com

For more information about the cf org-users command, see the Cloud Foundry CLI Reference Guide. Formore information about the cf space-users command, see the Cloud Foundry CLI Reference Guide.

Manage roles

You use the commands listed below to manage roles in the cf CLI. These commands require admin permissions and take username, org or space, and role asarguments:

  • cf set-org-role
    For more information, see the Cloud Foundry CLI Reference Guide.

  • cf unset-org-role
    For more information, see the Cloud Foundry CLI Reference Guide.

  • cf set-space-role
    For more information, see the Cloud Foundry CLI Reference Guide.

  • cf unset-space-role
    For more information, see the Cloud Foundry CLI Reference Guide.

The available roles are:

  • OrgManager
  • BillingManager
  • OrgAuditor
  • SpaceManager
  • SpaceDeveloper
  • SpaceAuditor

For more information about user roles, see Orgs, Spaces, Roles, and Permissions.

The following example shows the terminal output for cf set-org-role [emailprotected] example-org OrgManager, which assigns the Org Manager role to[emailprotected] within the example-org org:

Assigning role OrgManager to user huey@example.com in org example-org as username@example.com...OK

ImportantIf you are not an admin, you see this message when you try to run these commands: error code: 10003, message: Youare not authorized to perform the requested action

Manage roles for users with identical usernames in multiple origins

If a username corresponds to multiple accounts from different user stores, such as both the internal UAA store and an external SAML or LDAP store, runningeither cf set-org-role or cf unset-org-role returns an error similar to the following example:

The user exists in multiple origins. Specify an origin for the requested user from: ‘uaa’, ‘other’

To resolve this ambiguity, you can construct a curl command that uses the API to perform the desired role management function. For an example, see theCloud Foundry API documentation.

Push an app

These sections describe how to use the cf push command to push a new app or sync changes to an existing app.

For more information about the cf push command, see the Cloud Foundry CLI Reference Guide.

Push a new app or push changes to an app

To push an app:

  1. In a terminal window, log in to the cf CLI by running:

    cf login
  2. Go to the directory of the app.

  3. Push a new app or push changes to an app by running:

    cf push APP-NAME

    Where APP-NAME is the name of the app.

Push an app using a manifest

You can provide a path to a manifest file when you push an app. The manifest file includes information such as the name of the app, disk limit, and numberof instances. You can use a manifest file rather than adding flags to the cf push command.

cf push locates the manifest.yml file in the current working directory by default. Alternatively, you can provide a path to the manifest with the -fflag.

For more information about the -f flag, see the Cloud Foundry CLI Reference Guide.

NoteWhen you provide an app name at the command line, the cf push command uses that appname regardless of whether there is a different app name in the manifest. If the manifest configures multiple apps, you can push asingle app by providing thenname at the command line; the cf CLI does not push the others. Use these behaviors for testing.

Push an app with a buildpack

You can specify a buildpack when you push an app with the -b flag. If you use the -b flag to specify a buildpack, the app remains permanently linked tothat buildpack. To use the app with a different buildpack, you must delete the app and then push it again.

For more information about available buildpacks, see the Cloud Foundry documentation.

The following example shows the terminal output for cf push awesome-app -b ruby_buildpack, which pushes an app called awesome-app to the URLhttp://awesome-app.example.com and specifies the Ruby buildpack with the -b flag:

Pushing app awesome-app to org example-org / space development as [emailprotected]......Waiting for app awesome-app to start...name: awesome-apprequested state: startedroutes: awesome-app.example.comlast uploaded: Fri 16 Sep 01:54:16 UTC 2022stack: cflinuxfs3buildpacks: name version detect output buildpack name ruby_buildpack 1.8.58 ruby rubytype: websidecars:instances: 1/1memory usage: 1024Mstart command: bundle exec rackup config.ru -p $PORT -o 0.0.0.0 state since cpu memory disk logging details#0 running 2022-09-16T01:54:29Z 0.0% 0 of 0 0 of 0 0/s of 0/s

ImportantTo avoid security exposure, verify that you migrate your apps and custombuildpacks to use the cflinuxfs4 stack based on Ubuntu 22.04 LTS (Jammy Jellyfish). The cflinuxfs3 stack isbased on Ubuntu 18.04 (Bionic Beaver), which reaches end of standard support in April 2023.

Map a route to an app

You can provide a hostname for your app when you push the app. If you do not provide a hostname, the cf push command routes your app to a URL of the form APP-NAME.DOMAIN, where APP-NAME is the name of your app and DOMAIN is your default domain. The route definition is included in the manifest.yml file.

For information about mapping a route to your app, see Routes and domains.

To map a route to the app:

  1. In a terminal window, log in to the cf CLI by running:

    cf login
  2. Push and map a route by running:

    cf push -f manifest.yml --var host=APP-HOSTNAME

    Where:

    • APP-NAME is the name of the app.
    • APP-DOMAIN is the domain of the app.
    • APP-HOSTNAME is the hostname of the app.

Manage user-provided service instances

These sections describe how to create or update a service instance.

Create a service instance

To create a new service instance, use the cf create-user-provided-service or cf cups commands. For more information about thecf create-user-provided-service and cf cups commands, see the Cloud Foundry CLI ReferenceGuide.

To create or update a user-provided service instance, you must supply basic parameters. For example, a database service might require a username, password,host, port, and database name.

You can provide these parameters in the following ways:

  • Interactively. For more information, see Supply Parameters Interactively below.

  • Non-interactively. For more information, see Supply Parameters Non-Interactively below.

  • With third-party log management software as described in RFC 6587. For more information, see Supply Parameters Through a Third Party belowand RFC 6587.

When used with third-party logging, data is sent formatted according to RFC 5424. For more information, seeRFC 5424.

Supply parameters interactively

To create a new service while supplying parameters interactively:

  1. In a terminal window, log in to the cf CLI by running:

    cf login
  2. List parameters in a comma-separated list after the -p flag. Run:

    cf cups SERVICE -p "PARAMETER, SECOND-PARAMETER, THIRD-PARAMETER"

    Where:

    • SERVICE is the name of the service you want to create.
    • PARAMETER, SECOND-PARAMETER, and THIRD-PARAMETER are parameters such as username, password, host, port, and database name.

Supply parameters non-interactively

To create a new service while supplying parameters non-interactively:

  1. In a terminal window, log in to the cf CLI by running:

    cf login
  2. Pass parameters and their values in as a JSON hash, bound by single quotes, after the -p tag. Run:

    cf cups SERVICE -p '{"host":"HOSTNAME", "port":"PORT"}'

    Where:

    • SERVICE is the name of the service you want to create.
    • HOSTNAME and PORT are service parameters.

Supply parameters through a third party

For specific log service instructions, see Streaming app logs to third-party services.

To create a service instance that sends data to a third party:

  1. Log in to the cf CLI:

    cf login
  2. Create a service instance that sends data to a third party by running:

    cf cups SERVICE -l THIRD-PARTY-DESTINATION-URL

    Where:

    • SERVICE is the name of the service you want to create.
    • THIRD-PARTY-DESTINATION-URL is the external URL of the third-party service.

Bind and unbind service instances

After you create a user-provided service instance, you can:

  • Bind the service to an app with cf bind-service. For more information, see the Cloud Foundry CLI ReferenceGuide.

  • Unbind the service with cf unbind-service. For more information, see the Cloud Foundry CLI ReferenceGuide.

  • Rename the service with cf rename-service. For more information, see the Cloud Foundry CLI ReferenceGuide.

  • Delete the service with cf delete-service. For more information, see the Cloud Foundry CLI ReferenceGuide.

Update a service instance

To update one or more of the parameters for an existing user-provided service instance, use cf update-user-provided-service or cf uups.

For more information about the cf update-user-provided-service and cf uups commands, see the Cloud Foundry CLI ReferenceGuide.

The cf uups command does not update any parameter values that you do not supply.

Retrieve cf CLI return codes

The cf CLI uses exit codes, which help with scripting and confirming that a command has run successfully.

To view a cf CLI exit code:

  1. In a terminal window, log in to the cf CLI by running:

    cf login
  2. To check that the login was successful, run one of these commands, depending on your OS:

    • For Mac OS, run:

      echo $?
    • For Windows, run:

      echo %ERRORLEVEL%

If the command succeeds, the exit code is 0.

View CLI help output

The cf help command lists the cf CLI commands and a brief description of each. For more information, see the Cloud Foundry CLI ReferenceGuide.

To list detailed help for any cf CLI command, add the -h flag to the command.

The example below shows detailed help output for the cf delete command:

NAME: delete - Delete an appUSAGE: cf delete APP_NAME [-f -r]ALIAS: dOPTIONS: -f Force deletion without confirmation -r Delete any mapped routes (only deletes routes mapped to a single app)
Create a pull request or raise an issue on the source for this page in GitHub
Getting started with the cf CLI |
    Cloud Foundry Docs (2024)

FAQs

What is CF CLI? ›

Page last updated: February 6, 2024. The cf CLI is the official command line client for Cloud Foundry.

How to install CF CLI in VS Code? ›

Install CF CLI (Command Line Interface) for Cloud Foundry operations such as app deployment, service creation, etc. Go to the README file and then find the Downloads section. Select the installation version that you would like to install. Download the CF CLI installer for your OS and start installation on your machine.

What is the command to check the version in Cloud Foundry? ›

CLI: cf -v.

How to install CF CLI in Windows 10? ›

Install the cf CLI:
  1. For Microsoft Windows, unpack the ZIP file.
  2. For Mac OS, proceed as follows: Open the PGK file. In the installation wizard, choose Continue, and then select the destination folder for the cf CLI installation. Choose Continue, and when prompted, choose Install.

What is CLI and how does it work? ›

A command line interface (CLI) is a software mechanism you use to interact with your operating system using your keyboard. Another mechanism is a graphical UI (GUI), which is popular today with all applications and software systems.

What is Cloud Foundry CLI used for ___________? ›

These topics explain the Cloud Foundry Command Line Interface (cf CLI), a tool used to deploy and manage apps.

How to install CF CLI plugin? ›

You install plugins locally on your system using the cf install-plugin command. Detailed instructions on using plugins can be found at the Cloud Foundry site, but there are two main means of fetching plugins: You can download a compiled plugin binary from a remote site and install it from local disk.

How to login to Cloud Foundry CLI? ›

Log in with the CLI
  1. API-URL is your API endpoint, the URL of the Cloud Controller in your Cloud Foundry instance.
  2. USERNAME is your username.
  3. PASSWORD is your password. ...
  4. ORG is the org where you want to deploy your apps.
  5. SPACE is the space in the org where you want to deploy your apps.
Feb 6, 2024

What is CF push? ›

The cf CLI command cf push pushes apps to Cloud Foundry. There are two main ways to run the cf push command: Run cf push APP-NAME to push an app using default settings.

How to set environment variable in CF CLI? ›

  1. NAME. set-env - Set an env variable for an app.
  2. USAGE. cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE.
  3. ALIAS. se.
  4. SEE ALSO. apps, env, restart, set-running-environment-variable-group, set-staging-environment-variable-group, unset-env.

What is the CF target command? ›

cf target displays your current API endpoint, user, org and space. cf orgs prints a list of orgs that you can access. cf target -o org switches to a different org. cf spaces prints a list of spaces that you can access.

How do I check my Cloud Foundry logs? ›

To view logs, run the cf logs command. You can tail, dump, or filter log output. For more information about the cf logs command, see the Cloud Foundry CLI reference guide.

How do I install the CF tool? ›

Installation and setup of cf-tool

In a command window type cf config and then choose type 0 (username and password). Enter your username and password of code-forces. If everything goes well, cf tool will say login succeeded! Now you need to set templates in cf tools.

How do I install CLI tool? ›

Install Windows CLI Tool

The CLI Tool installer for Windows is delivered as an .exe file. Log into your local Windows computer as administrator and start the installation program in any of the following ways. In the Windows GUI, double-click the .exe file. In a cmd window, run the .exe.

Is Cloud Foundry open source? ›

Cloud Foundry is open-source software, and hence, it is available to anyone. Deploying Cloud Foundry involves interfacing with the underlying infrastructure using the Cloud Foundry BOSH deployment system, another open-source tool governed by the Cloud Foundry Foundation.

What is Shopify CLI used for? ›

Shopify CLI is a command-line interface tool that helps you build Shopify apps and themes. It quickly generates Shopify apps, themes, and custom storefronts. You can also use it to automate many common development tasks. This documentation explains how to use Shopify CLI for theme development.

How do I delete apps from CF CLI? ›

To delete an app with no services, run cf delete -r APP-NAME . Replace APP-NAME with the name of the app. The -r option instructs the cf CLI to removes routes associated with the app. Important In cf CLI v7+, -r no longer deletes routes when the route is mapped to more than one app.

What is the CLI in CS? ›

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

What is Microsoft CLI? ›

The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. The Azure CLI is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation.

Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 6279

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.