Thursday, June 6, 2024

 

DOCKERIZING AN APP

Your team is developing the train timetable app. They intend to switch to using containers to operate the program in production. The app will have to be built into a Docker image. The team has asked you to create a Dockerfile for the train scheduler app. It must also be verified so it can be used to create an image and run in a container.

 

TASKS 

CREATE A DOCKERFILE FOR THE APPLICATION 

Fork the same source code on GitHub 

clone your fork 

create a docker file 

 

BUILD A DOCKER IMAGE USING THE DOCKER FILE

use docker build to build the docker image. 

use docker run to run a container using the image 

verify the app is running by accessing the trains schedule app.

 

 

Create a Dockerfile for the Application

Ø  Navigate to the GitHub source code.

Ø  Create a personal fork of the source repository by clicking the Fork icon in the upper right corner of GitHub.

Ø  To create a Docker file, select Create new file.

Ø  Name the new file Dockerfile.

Ø  Include the following information in the new Dockerfile.

 

FROM node:carbon

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 8080

CMD [ "npm", "start" ]

 

Ø  Commit file by clicking Commit new file located at the bottom of the page.

Ø  Copy the URL of your GitHub fork.

 

Build a Docker Image Using the Dockerfile and Run It

 

Ø  Login the Cloud Server

Ø  Change to home directory:

cd ~/

Ø  Clone your personal fork of the source code repository using the copied URL GitHub repository:

git clone https://github.com/insertyourusernamehere/cicd-pipeline-train-schedule-docker

Ø  Change directory into the new folder:

cd cicd-pipeline-train-schedule-docker/

Ø  Verify GitHub file exists:

ls -la

Ø  View contents of the folder:

cat Dockerfile

Ø  Build a Docker image.

sudo docker build -t <your username>/train-schedule .

Ø  Run Docker application:

sudo docker run -p 8080:8080 -d <your username>/train-schedule

Ø  List and verify current running processes in Docker container:

sudo docker ps

Ø  Confirm the train schedule app is available by navigating to URL:

http://Public IP>:8080

 

 

 

 

 

No comments:

Post a Comment

  PROMETHEUS AND GRAFANA A robust performance monitoring and alerting stack is crucial to service reliability. Cloud Native Computing Foun...