Deploy a containerized app to IBM Cloud Foundry
Tags: tutorial, node, cloud, docker
Published: 2021-09-01 16:50:08

Welcome to back to THINK Days!

In this hands-on tutorial, you will deploy a "Hello world" Node.js application to IBM Cloud using [Cloud Foundry](https://www.ibm.com/cloud/cloud-foundry). Things you will be able to learn after completing this tutorial:
 - Run an application using Cloud Foundry on IBM Cloud
 - Launch the `IBM Cloud Shell` on https://www.cloud.ibm.com
 - Discover IBM Cloud CLI to deploy applications to Cloud Foundry

## What is Cloud Foundry?
Cloud Foundry is provided as a PaaS(Platform as a Service) that enables developers to build, deploy, test, and scale applications without having to manually configure and manage servers.

### Pre-requisites:
An IBM Cloud account – (sign up for a free account)
A basic, foundational knowledge of NodeJS

Let's get started!

### Launch the IBM Cloud Shell

To start this tutorial, we'll be using the IBM Cloud Shell, which is available by clicking on the terminal icon on the top right:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwl582r0v4apa59rgdr0.png)

Once loaded, you'll be presented with an embedded web terminal that has the `ibmcloud CLI` and other tools available.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2849j4w25pqnngl59zx.png)
 
### Clone the NodeJS Starter App from IBM Repo

After setting up our CLI, the second thing we'll do is clone the code repository that has the source code for the Cloud Essentials app we want to deploy in our IBM Cloud Shell. Copy the following command into the terminal we opened up previously:
```
git clone https://github.com/IBM/node-hello-world
```
Go into the directory of the cloned repository with this command:
```
cd node-hello-world
```
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rmljwnlo18vb8i7omz0.png)

 
### Deploy the app to IBM Cloud Foundry
Next, to deploy the application with Cloud Foundry we first we need to target a Cloud Foundry API endpoint. To do this, run the following interactive command.
```
ibmcloud target --cf
```
You should see output like the example below:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy3jh59xxvkow5wrcf14.png)

#### NOTE:
If you run into a `No organizations found` or `No space targeted` error please create a new Cloud Foundry organization and space by running the following commands:
```
ibmcloud account org-create <your-ibm-cloud-email-address>
```
and then
```
ibmcloud account space-create dev_space -o <your-ibm-cloud-email-address>
```
and re-run the command to fix errors
```
ibmcloud target --cf
```

Finally to deploy the application, we do a simple cf push as such:
```
ibmcloud cf push
```

### Access the deployed app

Navigate to the URL that is show in the routes value, for example:
```
https://node-hello-world-example-surprised-kudu-ec.mybluemix.net
```
If all goes well - you should see Hello World at the top-left corner of your screen.

### Deleting the app and stopping service
Now while we love to explore no one wants to get charged for the apps in Cloud Foundry. So to stop or delete the service we can either go to our resource list and delete it or we can use the CLI to delete the deployment as such:
```
ibmcloud cf delete node-hello-world-example -f -r
```

Oila! You have successfully deployed a NodeJS app onto IBM Cloud Foundry using the IBM Cloud Shell.

Thank you for following along this THINK Day's Tutorial and be sure to look out for my next post, where I will continue sharing my Journey with IBM Cloud Services!!!

==== Follow me on Social Media(`@mrinasugosh`) ====
Dev.to: @mrinasugosh 
Github: [@mrinasugosh](https://github.com/mrinasugosh)
Twitter: [@mrinasugosh](https://twitter.com/mrinasugosh)
LinkedIn: [@mrinasugosh](https://www.linkedin.com/in/mrinasugosh/)