In this series, we are previewing the Cloud Foundry for Developers training course to help you better understand what Cloud Foundry is and how to use it. So far, we’ve covered:
For more details, you can download the sample chapter here.
The Cloud Foundry command-line interface (cf CLI) is your primary tool for interacting with your Cloud Foundry instances: manage apps, view logs, run health checks, manage buildpacks, manage users, and manage plugins. Today, we will learn how to install the tool and run commands. You’ll need a Cloud Foundry instance; see How Can I Try Out Cloud Foundry? to learn about some hosting providers to try, some of them free.
Install the cf CLI by following the instructions at Installing the cf CLI. Verify that it installed correctly by checking the version:
$ cf --version cf version 6.30.0
The cf CLI supports localization. The default language setting is en-US. To change it follow the directions at Installing the cf CLI: Localize. This controls the language only for the cf CLI, and does not affect your system settings.
Getting Started with the cf CLI
The cf CLI has an inbuilt help system.
cf --help displays the main help menu, and you can get help on specific commands with
cf [command name] --help, for example:
$ cf login --help
The first step to interacting with a Cloud Foundry instance, also called a target, is to log in. You are logging into an API endpoint, using this syntax:
cf login api.cloudfoundry.system.domain. It will always have the
For example, to log into Pivotal Web Services located at
run.pivotal.io, your target is
Orgs And Spaces
When you log in, you are asked to target an org and a space. If there is only one org and one space these become your default targets. When there are multiple orgs and spaces then you must specify the ones you want.
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.
cf target -s space switches to a different space.
Correct cf CLI Version
It is possible for multiple Cloud Foundry targets to run different versions, so you should verify that your CLI version works with your current target. Use the
cf curl command to determine version information.
All Cloud Foundry targets expose an info endpoint, which prints the release name, build number, description, and various endpoints. Run
cf curl /v2/info to see this information, and look for the
"min_cli_version". The version you installed should be equal to or newer than the
Debugging Connection Issues
The CF_TRACE environment variable prints API request diagnostics, showing your login API, cf CLI version, API version, and lot of other useful information. First set the environment variable, then run the
cf target command:
$ export CF_TRACE=true $ cf target
Unset it with
export CF_TRACE=false. Or you can use it per command by prepending your commands:
$ CF_TRACE=true cf target
Now that you know the basics of using cf CLI, come back for the fifth and final blog to learn how to create and push a simple app.
The information in this series is based on the Cloud Foundry for Developers (LFD232) training course from Cloud Foundry and The Linux Foundation. You can download a sample chapter from the course here.