# Deploying a Docker Container with Jenkins Pipelines

## Task 1: Configure Jenkins to run the new dockerized train-schedule pipeline

To accomplish this, you will need to do the following setup in Jenkins:

**Configure Jenkins credentials for the production server:**

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2F1O0DHRKMarO3VX6uq9Kw%2Fimage.png?alt=media&#x26;token=0d7f6c94-4a6f-4c53-bf41-84fa81fba6ce" alt=""><figcaption></figcaption></figure>

Add the value to the browser. Finish install of Jenkins

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FdqVmbj3SU6Bj36uMgqim%2Fimage.png?alt=media&#x26;token=adf735eb-e8ec-4c8c-a827-5076c077de52" alt=""><figcaption></figcaption></figure>





**Using the `cloud_user` password, create a Jenkins credential called&#x20;**_**deploy**_**.**

Dashboard -> Manage -> Jenkins Credentials

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FsuOSc3DlSVqhEmlIXUCo%2Fimage.png?alt=media&#x26;token=3f887d5d-e941-495a-a87d-f42460ffa627" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FKPtUr3AAWBP1sjhTpjl6%2Fimage.png?alt=media&#x26;token=4417951c-f7c0-4339-bb7d-538eedde0459" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2F0ScHyKKS0jQD8plPt16N%2Fimage.png?alt=media&#x26;token=9ab27031-acee-4809-8f81-c4af3c59d423" alt=""><figcaption></figcaption></figure>

**Configure Jenkins credentials for the Docker image registry (Docker Hub).**

Dashboard -> Manage -> Jenkins Credentials

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2Fzya6z5pamVbxzOMbWWAg%2Fimage.png?alt=media&#x26;token=944c2121-aeb3-412a-b7cd-f6f6b6b4bfe4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2Fw0ibGkeJMza9XuLidZjV%2Fimage.png?alt=media&#x26;token=c69c7233-b213-45a4-9d35-234101764198" alt=""><figcaption></figcaption></figure>

\<Make docker hub accounts>

1. Create a Jenkins credential called _docker\_hub\_login_. You will need a docker hub account in order to perform this step.
2. Configure a global property in Jenkins to store the production server IP.
3. Create a global property in Jenkins called _prod\_ip_ and set it to the _Production Server Public IP_ that appears on the learning activity page once the servers are started up.
4. Create a multibranch pipeline project in Jenkins called _train-schedule_.
5. Configure the Jenkins project to pull from your fork of the source code.
6. Make a fork of the Git repo at: [https://github.com/linuxacademy/cicd-pipeline-train-schedule-dockerdeploy](https://github.com/linuxacademy/cicd-pipeline-train-schedule-dockerdeploy)



## Task 2: Successfully deploy the train-schedule app to production as a Docker container using the Jenkins Pipeline

1. Implement the following new stages in the Jenkinsfile:

* `Build Docker Image`: Build a Docker image with the runnable code inside it.
* `Push Docker Image`: Push the image to Docker Hub.
* `DeployToProduction`: Deploy the new image to production.
* Stop and remove any older containers.
* Pull and run the newly built image.

1. After implementing these stages, run the build in Jenkins to deploy the application to production!

