cf Command Line Interface Setup in Ubuntu

Cloud Foundry CLI is the official command line client for Cloud Foundry. In this blog post, I will show you on how to deploy an application in Cloud Foundry using this tool. It is very easy to use this CLI once it is correctly installed and set up.

In order to log into cf, you need to create an account in You can sign up for free for 60 day free trial which requires no credit card. Please Remember the credentials, because you need them later to login to cf.

Getting started

Latest stable

Download and run the installer for your platform from here. You can find the installer or compressed binary for your platform from there. 

Command line

If you prefer installing cf cli via command line, Ubuntu users can use the following command. 

$ curl -L "" | tar -zx

Log in

Once installed, you can log in to cloud foundry using cf cli.
$ cf login
API endpoint:
Targeted org nanduni-org
Targeted space development
API endpoint: (API version: 2.48.0)   
Org:            nanduni-org   
Space:          development 
If you are using cf for the first time, this will ask you to create organizations, spaces required etc.

Push an application

Now, go to the base directory that contains your application and execute the following command.
$ cf push mytomcat
Creating app mytomcat in org nanduni-org / space development as
Creating route
Binding to mytomcat...
Uploading mytomcat...
Uploading app files from: /home/nanduni/apache-tomcat-7.0.67/webapps/Servlet3
Uploading 3.2K, 7 files
Done uploading               
Starting app mytomcat in org nanduni-org / space development as
Downloading go_buildpack...
Downloading java_buildpack...
Downloading ruby_buildpack...
Downloading python_buildpack...
Downloading nodejs_buildpack...
Downloading staticfile_buildpack...
Downloading php_buildpack...
Downloading liberty_buildpack...
Downloading binary_buildpack...
Downloaded binary_buildpack
Downloaded php_buildpack
Downloaded java_buildpack
Downloaded ruby_buildpack
Downloaded liberty_buildpack
Downloaded python_buildpack
Downloaded nodejs_buildpack
Downloaded go_buildpack
Downloaded staticfile_buildpack
Creating container
Successfully created container
Downloading app package...
Downloaded app package (2.3K)
-----> Java Buildpack Version: v3.5.1 |
-----> Downloading Open Jdk JRE 1.8.0_65 from (1.1s)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from (0.0s)
       Memory Settings: -Xss1M -Xmx768M -XX:MaxMetaspaceSize=104857K -Xms768M -XX:MetaspaceSize=104857K
-----> Downloading Tomcat Instance 8.0.30 from (0.3s)
       Expanding Tomcat Instance to .java-buildpack/tomcat (0.1s)
-----> Downloading Tomcat Lifecycle Support 2.5.0_RELEASE from (0.0s)
-----> Downloading Tomcat Logging Support 2.5.0_RELEASE from (0.0s)
-----> Downloading Tomcat Access Logging Support 2.5.0_RELEASE from (0.0s)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (52.3M)
Uploaded droplet (51.1M)
Uploading complete
1 of 1 instances running
App started
App mytomcat was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) &&  JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/ $CALCULATED_MEMORY -Daccess.logging.enabled=false -Dhttp.port=$PORT" exec $PWD/.java-buildpack/tomcat/bin/ run`
Showing health and status for app mytomcat in org nanduni-org / space development as
requested state: started
instances: 1/1
usage: 1G x 1 instances
last uploaded: Wed Jan 27 05:54:32 UTC 2016
stack: cflinuxfs2
buildpack: java-buildpack=v3.5.1- open-jdk-like-jre=1.8.0_65 open-jdk-like-memory-calculator=2.0.1_RELEASE tomcat-access-logging-support=2.5.0_RELEASE tomcat-instance=8.0.30 tomcat-lifecycle-support=2.5.0...
     state     since                    cpu    memory          disk  details   
#0   running   2016-01-27 11:25:10 AM   0.0%   109.2M of 1G   129.5M of 1G      

When you push an app, Cloud Foundry determines which buildpack to use. Each buildpack has a position in the detection priority list. Cloud Foundry first checks whether the buildpack in position 1 is right for the app. If the position 1 buildpack is not appropriate, Cloud Foundry moves on to the position 2 buildpack. This goes on until Cloud Foundry finds the correct buildpack.

I no matching buildpack is found, cf push fails with an error like below.

None of the buildpacks detected a compatible application
Exit status 222
Staging failed: Exited with status 222

The available buildpacks can be checked using the following command.

$ cf buildpacks
Getting buildpacks...
buildpack              position   enabled   locked   filename   
staticfile_buildpack   1          true      false   
java_buildpack         2          true      false   
ruby_buildpack         3          true      false   
nodejs_buildpack       4          true      false   
go_buildpack           5          true      false   
python_buildpack       6          true      false   
php_buildpack          7          true      false   
liberty_buildpack      8          true      false   
binary_buildpack       9          true      false   

I hope that this blog post would be useful for anyone who is interested in deploying applications in cloud foundry using cf cli.


Post a Comment