Running Jenkins on Docker for Windows

A Step-by-Step Guide to Running Jenkins in Docker on Windows

Running Jenkins using Docker on Windows simplifies its installation and ensures a clean, isolated environment. Here's how I achieved this setup

Prerequisites

Docker for Desktop: Make sure Docker is installed and running on your Windows machine.

Step 1: Install Docker for Desktop and Start It

  1. Download and install Docker for Desktop from the official site.

  2. Launch Docker Desktop and ensure it is running.

Step 2: Run Jenkins in Docker

2.1 Download Jenkins Image

Pull the official Jenkins image using the following Docker command:

docker pull jenkins/jenkins:lts

Run command on dokcer terminal

2.2 Run Jenkins Container with Volume Attached

To persist Jenkins data (e.g., configurations, plugins, and jobs), run the container with a volume attached:

docker run -d -p 8080:8080 -p 50000:50000 --name my-jenkins -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

Run command on docker terminal

  • -d: Runs the container in detached mode.

  • -p 8080:8080: Maps the Jenkins UI to port 8080.

  • -p 50000:50000: Maps the port for Jenkins agents.

  • -v jenkins_home:/var/jenkins_home: Attaches a named volume to store Jenkins data.

Step 3: Access Jenkins via the Browser

  1. Open your browser and navigate to http://localhost:8080.

  2. You'll see the Jenkins unlock screen.

Step 4: Retrieve the Administrator Password

  1. Access the Jenkins logs or open a shell in the container:

     docker exec -it my-jenkins cat /var/jenkins_home/secrets/initialAdminPassword
    

    Run command on docker terminal

  2. Copy the displayed password and paste it into the unlock screen.

Step 5: Install Plugins

  1. Once unlocked, Jenkins will prompt you to install plugins.

  2. Choose "Install suggested plugins" to set up commonly used plugins.

  3. Add details

  4. Click on Save and Finish - Start Jenkins

Step 6: Create and Run a Sample Job

  1. Log in to the Jenkins dashboard.

  2. Click on "New Item" to create a new job.

  3. Choose "Freestyle project" and name your job.

  4. Configure the job with a simple build step. For example, add a shell command:

echo "Hello, Jenkins!"

Follow below step

  1. Save the job and click "Build Now" to run it.

  2. View the build output in the "Console Output" section.

If you found my post helpful, feel free to show your support by buying me a coffee! ☕

0
Subscribe to my newsletter

Read articles from vikas bhaskar vooradi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

vikas bhaskar vooradi
vikas bhaskar vooradi

In my free time, I enjoy coding, blogging, and exploring technology-related content on the internet.