0% found this document useful (0 votes)
10 views5 pages

Exp 10 Sepm

This document outlines the steps to set up Docker and Jenkins on Windows, including installation, configuration, and creating a simple web application using Nginx. It details the creation of a Dockerfile and Jenkinsfile for containerization and automation, as well as the process to push the project to GitHub and configure Jenkins to build and run the container. Finally, it provides instructions for verifying the setup and managing Docker containers.

Uploaded by

Aryan Kate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Exp 10 Sepm

This document outlines the steps to set up Docker and Jenkins on Windows, including installation, configuration, and creating a simple web application using Nginx. It details the creation of a Dockerfile and Jenkinsfile for containerization and automation, as well as the process to push the project to GitHub and configure Jenkins to build and run the container. Finally, it provides instructions for verifying the setup and managing Docker containers.

Uploaded by

Aryan Kate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment No: 10

Step 1: Install Docker on Windows (with WSL 2)


1. Enable WSL 2 & Install Ubuntu (Linux Kernel)
2. Open PowerShell as Administrator and run:

wsl --install

3. Restart your computer.


4. Set Ubuntu as the default WSL distribution:

wsl --set-default-version 2

2. Install Docker Desktop

1. Download Docker Desktop for Windows →


https://www.docker.com/products/docker-desktop/
2. Click Download Docker Desktop for Windows.
3. Save the .exe file.
4. During installation, enable: ✅ Use WSL 2 instead of Hyper-V

5. Restart your PC after installation.


6. Open PowerShell as admin and check if Docker is running:

docker version

3. Change Jenkins Service to Run as a User

1. Open services.msc (Win + R, type services.msc, Enter).


2. Find Jenkins, right-click → Properties.
3. Go to the "Log On" tab.
4. Select "This account" → Enter your Windows username & password.
5. Click Apply, then OK.
6. Restart Jenkins.

4. Add Jenkins User to Docker Group

1. Open PowerShell as Administrator.


2. Run:

net localgroup docker-users "YOUR-USERNAME" /add

(Replace YOUR-USERNAME with the actual username running Jenkins.)

3. Restart Docker & Jenkins.


Step 2: Create a New Project
1️. Create the Root Project Directory

cd C:\Users\Admin\myfirst
mkdir DockerJenkinsExperiment

cd DockerJenkinsExperiment

Step 3: Create the Web App


We’ll use a simple index.html file served by Nginx.

1️. Create a webapp Directory

mkdir webapp
cd webapp
notepad index.html

2️. Add This HTML Code to index.html

<!DOCTYPE html>
<html>
<head>
<title>Docker Jenkins Experiment</title>
</head>
<body>
<h1>Hello from Docker!</h1>
</body>
</html>

 Save and close the file.


 Go back to the root folder:

cd ..

Step 4: Create the Dockerfile


cd C:\Users\Admin\myfirst\DockerJenkinsExperiment

1️⃣ Create a Dockerfile in the Root Directory

notepad Dockerfile

2️⃣ Add the Following Content

FROM nginx:latest
COPY webapp /usr/share/nginx/html
EXPOSE 80
This will:

 Use the nginx image.


 Copy the webapp folder into the Nginx web server.
 Expose port 80 for HTTP traffic.
 Save and close the file.

Step 5: Create the Jenkinsfile


1️⃣ Create a Jenkinsfile in the Root Directory (cd
C:\Users\Admin\myfirst\DockerJenkinsExperiment)

notepad Jenkinsfile

2️⃣ Paste This Pipeline Script

pipeline {

agent any

stages {

stage('Checkout Code') {

steps {

git branch: 'main', url: 'https://github.com/name/myfirst.git'

stage('Build Docker Image') {

steps {

dir('DockerJenkinsExperiment') { // Ensure Docker build happens in the


right folder

sh 'ls -l' // Debugging: List files to check if Dockerfile exists

sh 'docker build -t my-docker-webapp .' // Build Docker Image

}
}

stage('Run Docker Container') {

steps {

sh 'docker run -d -p 8081:80 my-docker-webapp'

What this does:


✅ Pulls code from GitHub
✅ Builds a Docker image (my-docker-webapp)
✅ Runs a container on port 8081

 Save and close the file.

Step 6: Push the Project to GitHub


1️. Add and Commit Files

git add .
git commit -m "Added Docker experiment files"

2️. Push to GitHub

git branch -M main


git push -u origin main

Step 7: Configure Jenkins Pipeline


1️. Open Jenkins Dashboard → New Item
2️. Enter Job Name: DockerJenkinsExperiment
3️. Select Pipeline → Click OK
4️. Scroll to Pipeline Definition
5️. Select Pipeline script from SCM
6️. Set SCM to Git
7️. Enter your GitHub Repository URL
https://username:token@github.com/username/myfirst.git

8️. Set Branch: main


9️. Script Path: DockerJenkinsExperiment/Jenkinsfile
10. Click Save and Build Now

Step 8: Verify if It Works


Once the build is complete, open your browser and visit:

http://localhost:8081

You should see your html page

Summary of What You Did

 Used your GitHub repo


 Set up a simple web app with HTML
 Wrote a Dockerfile to containerize it
 Created a Jenkinsfile for automation
 Configured Jenkins to build & run the container

Note* to delete old container run the following commands in powershell (admin mode)

docker ps : this will show you the running container

docker stop <container_id>

docker rm <container_id>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy