Deploy an Application
Page last updated:
You deploy an app to Cloud Foundry by running a
cf push command from the Cloud Foundry Command Line Interface (cf CLI).
Refer to the Installing the cf CLI topic for more information.
Between the time that you run
cf push and the time that the app is available, Cloud Foundry performs the following tasks:
- Uploads and stores app files
- Examines and stores app metadata
- Creates a “droplet” (the Cloud Foundry unit of execution) for the app
- Selects an appropriate Diego cell to run the droplet
- Starts the app
For more information about the lifecycle of an app, see the Application Container Lifecycle topic.
An app that uses services, such as a database, messaging, or email server, is not fully functional until you provision the service and, if required, bind the service to the app. For more information about services, see the Services Overview topic.
Before you deploy your app to Cloud Foundry, make sure that:
Your app is cloud-ready. Cloud Foundry behaviors related to file storage, HTTP sessions, and port usage may require modifications to your app.
All required app resources are uploaded. For example, you may need to include a database driver.
Extraneous files and artifacts are excluded from upload. You should explicitly exclude extraneous files that reside within your app directory structure, particularly if your app is large.
An instance of every service that your app needs has been created.
Your Cloud Foundry instance supports the type of app you are going to deploy, or you have the URL of an externally available buildpack that can stage the app.
For help preparing to deploy your app, see:
Before you can push your app to Cloud Foundry you need to know:
- The API endpoint for your Cloud Foundry instance. Also known as the target URL, this is the URL of the Cloud Controller in your Cloud Foundry instance.
- Your username and password for your Cloud Foundry instance.
- The organization and space where you want to deploy your app. A Cloud Foundry workspace is organized into organizations, and within them, spaces. As a Cloud Foundry user, you have access to one or more organizations and spaces.
Cloud Foundry directs requests to an app using a route, which is a URL made up of a host and a domain.
The name of an app is the default host for that app, unless you specify the host name with the
Every app is deployed to an app space that belongs to a domain. Every Cloud Foundry instance has a default domain defined. You can specify a non-default, or custom, domain when deploying, provided that the domain is registered and is mapped to the organization which contains the target app space.
Note: CF allows app names, but not app URLs, to include underscores. CF converts underscores to hyphens when setting a default app URL from an app name.
The URL for your app must be unique from other apps hosted by Cloud Foundry. Use the following options with the cf CLI to help create a unique URL:
-nto assign a different HOST name for the app
--random-routeto create a URL that includes the app name and random words
cf help push to view other options for this command.
For more information about domains, see Routes and Domains.
Before you deploy, you need to decide on the following:
- Name: You can use any series of alpha-numeric characters as the name of your app.
- Instances: Generally speaking, the more instances you run, the less downtime your app will experience. If your app is still in development, running a single instance can simplify troubleshooting. For any production app, we recommend a minimum of two instances.
- Memory Limit: The maximum amount of memory that each instance of your
app can consume.
If an instance exceeds this limit, Cloud Foundry restarts the instance.
Note: Initially, Cloud Foundry immediately restarts any instances that exceed the memory limit. If an instance repeatedly exceeds the memory limit in a short period of time, Cloud Foundry delays restarting the instance.
- Start Command: This is the command that Cloud Foundry uses to start each instance of your app. This start command varies by app framework.
- Subdomain (host) and Domain: The route, which is the combination of subdomain and domain, must be globally unique. This is true whether you specify a portion of the route or allow Cloud Foundry to use defaults.
- Services: Apps can bind to services such as databases, messaging, and key-value stores. Apps are deployed into app spaces. An app can only bind to a service that has an existing instance in the target app space.
You can define deployment options on the command line, in a manifest file, or
See Deploying with Application Manifests to learn how
app settings change from push to push, and how command-line options,
manifests, and commands like
cf scale interact.
When you deploy an app while it is running, Cloud Foundry stops all instances of that app and then deploys.
Users who try to run the app get a “404 not found” message while
cf push runs.
Stopping all instances is necessary to prevent two versions of your code from running at the same time.
A worst-case example would be deploying an update that involved a database
schema migration, because instances running the old code would not work and
users could lose data.
Cloud Foundry uploads all app files except version control files with
To exclude other files from upload, specify them in a
.cfignore file in the
directory where you run the push command.
This technique is similar to using a
For more information, see the Ignore Unnecessary Files When Pushing section of the Considerations for Designing and Running an Application in the Cloud topic.
For more information about the manifest file, see the Deploying with Application Manifests topic.
Note: The Java buildpack does not support pre-runtime hooks.
To configure pre-runtime hooks, create a file named
.profile and place it in the root of your app directory.
If the directory includes a
.profile script, then Cloud Foundry executes it immediately before each instance of your app starts.
.profile script executes after the buildpack, the script has access to the language runtime environment created by the buildpack.
Note: Your app root directory may also include a
.profile.d directory that contains bash scripts that perform initialization tasks for the buildpack.
Developers should not edit these scripts unless they are using a custom buildpack.
You can use the
.profile script to perform app-specific initialization tasks, such as setting custom environment variables.
Environment variables are key-value pairs defined at the operating system level.
These key-value pairs provide a way to configure the apps running on a system.
For example, any app can access the LANG environment variable to determine which language to use for error messages and instructions, collating sequences, and date formats.
To set an environment variable, add the appropriate bash commands to your
.profile file. See the example below.
# Set the default LANG for your apps export LANG=en_US.UTF-8
Note: If you are using a PHP buildpack version prior to v4.3.18, the buildpack does not execute your PHP app’s
.profile script. Your PHP app will host the
.profile script’s contents.
This means that any PHP app staged using the affected PHP buildpack versions can leak credentials placed in the
Run the following command to deploy an app without a manifest:
cf push APP-NAME
If you provide the app name in a manifest, you can reduce the command to
See Deploying with Application Manifests.
Because all you have provided is the name of your app,
cf push sets the
number of instances, amount of memory, and other attributes of your app
to the default values.
You can also use command-line options to specify these and additional
The following transcript illustrates how Cloud Foundry assigns default values
to app when given a
cf push command.
Note: When deploying your own apps, avoid generic names like
my-app. Cloud Foundry uses the app name to compose the route to the app, and deployment fails unless the app has a globally unique route.
$ cf push my-app Creating app my-app in org example-org / space development as email@example.com... OK Creating route my-app.shared-domain.example.com... OK Binding my-app.shared-domain.example.com to my-app... OK Uploading my-app... Uploading app: 560.1K, 9 files OK Starting app my-app in org example-org / space development as firstname.lastname@example.org... -----> Downloaded app package (552K) OK -----> Using Ruby version: ruby-1.9.3 -----> Installing dependencies using Bundler version 1.3.2 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment Installing rack (1.5.1) Installing rack-protection (1.3.2) Installing tilt (1.3.3) Installing sinatra (1.3.4) Using bundler (1.3.2) Updating files in vendor/cache Your bundle is complete! It was installed into ./vendor/bundle Cleaning up the bundler cache. -----> Uploading droplet (23M) 1 of 1 instances running App started Showing health and status for app my-app in org example-org / space development as email@example.com... OK requested state: started instances: 1/1 usage: 1G x 1 instances urls: my-app.shared-domain.example.com state since cpu memory disk #0 running 2014-01-24 05:07:18 PM 0.0% 18.5M of 1G 52.5M of 1G
If you bound a service to the app that you deployed, you might need to configure your app with the service URL and credentials. For more information, see the specific documentation for your app framework:
If your app does not start on Cloud Foundry, first ensure that your app can run locally.
You can troubleshoot your app in the cloud using the cf CLI. See Troubleshoot Application Deployment and Health.Create a pull request or raise an issue on the source for this page in GitHub