Installing JENKINS through Docker File For Windows Container
In this blog, we will show you installing JENKINS through docker file for Windows container onWindowss 2016.
REQUIREMENTS
- Windows Container Host
- JENKINS setup file
DOWNLOAD JENKINS
- Go to the URL https://jenkins.io/download/
- Scroll down and click on the Windows link
- It prompts us to download the zip file.
- Once the download is complete and extracts the MSI from the ZIP file.
PREPARING BUILD ENVIRONMENT
- Create a folder named Jenkins in C:\ drive using below command
New-Item -Type Directory -Name jenkins -Path c:\
- Create one more folder name source inside C:\jenkins folder.
New-Item -Type Directory -Name setup -path C:\jenkins\
- Create a filename dockerfile inside c:\jenkins folder.
New-Item -Type File -Name dockerfile -Path C:\jenkins\
- Copy the downloaded jenkins setup file to c:\jenkins\setup folder.
- Open the dockerfile in the notepad and add the below code and save it.
#THIS DOCKER FILE IS DEVELOPED BY ASSISTANZ NETWORKS
#SPECIFY THE CONTAINER IMAGE
FROM microsoft/windowsservercore
#COPY THE JENKINS INSTALLATION FILES INTO THE CONTAINER
ADD ./setup c:/jenkins
#INSTALLING IIS
RUN Powershell.exe -Command Install-WindowsFeature Web-Server
#INSTALLING JENKINS
RUN ["msiexec.exe", "/i", "C:\\jenkins\\jenkins.msi", "/qn"]
#REMOVING SETUP FILES FROM CONTAINER
RUN Powershell.exe -Command remove-item c:/jenkins –Recurse
BUILDING THE IMAGE
- Go-to PowerShell and execute the below command to build the jenkins image.
docker build -t jenkins c:\jenkins
- It will take several minutes to complete the build.
CONFIGURE JENKINS
- Launch a new container using the Jenkins image which we built earlier.
docker run -it jenkins powershell
- Once the container is created, type ipconfig to find the IP address.
- Browse the IP along with port 8080 from your container host. It prompts for the initial administrator password to configure Jenkins.
- Type the below command to view the administrator password from the initialadminpassword file.
type ‘C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword’
- Copy & paste the password and click continue.
- In the next screen, select the plugins to be installed for your environment. For this demo, we have installed all the suggested plugins for Jenkins.
- It will take few minutes to complete the installation.
- In next screen, it prompts for to create a new admin user. Provide the details and click save and finish.
- The final screen shows that Jenkins is ready. Click on Start using Jenkins button.
- Now jenkins is available for our environment.
- You can download the pre-built image from the Docker Hub URL
https://hub.docker.com/r/assistanz247/jenkins-windows/
- Also, you can download the dockerfile from GitHub URL.
https://github.com/assistanz247/JENKINS
VIDEO
Thanks for reading this blog. We hope it was useful for you to learn to how to install Jenkins in windows container.
Hi,
thanks for the good guide. How can i handle persistent data, in case of changing to a container with a newer Jenkins version?
BR
Mario
Hi Mario,
Thanks for your comment. You can follow the below link to configure the persistent data volume inside a container.
https://www.assistanz.com/creating-container-volumes-in-windows-2016/
Regards,
Loges
Hi,
I am trying to install Jenkins through Docker , by following the steps you have given.
But I am getting the following error :
Sending build context to Docker daemon 122.4MB
Step 1/5 : FROM microsoft/windowsservercore
—> 8d57c0984795
Step 2/5 : ADD ./setup c:/jenkins
—> Using cache
—> 6c1aa7b19915
Step 3/5 : RUN Powershell.exe -Command Install-WindowsFeature Web-Server
—> Using cache
—> f89508a781d4
Step 4/5 : RUN [“msiexec.exe”, “/i”, “C:/jenkins/setup/jenkins.msi”, “/qn”]
—> Running in ee0df67c146e
‘[“msiexec.exe”’ is not recognized as an internal or external command,
operable program or batch file.
The command ‘cmd /S /C [“msiexec.exe”, “/i”, “C:/jenkins/setup/jenkins.msi”, “/qn”]’ returned a non-zero code: 1
Could you please help?
Hi Arc,
Thanks for reading this blog. We have tried this code and its work on our end. Can you please use the below code
#THIS DOCKER FILE IS DEVELOPED BY ASSISTANZ NETWORKS
#SPECIFY THE CONTAINER IMAGE
FROM microsoft/windowsservercore
#COPY THE JENKINS INSTALLATION FILES INTO THE CONTAINER
ADD ./setup c:/jenkins
#INSTALLING IIS
RUN Powershell.exe -Command Install-WindowsFeature Web-Server
#INSTALLING JENKINS
RUN ["msiexec.exe", "/i", "C:\\jenkins\\jenkins.msi", "/qn"]
#REMOVING SETUP FILES FROM CONTAINER
RUN Powershell.exe -Command remove-item c:/jenkins –Recurse
Regards,
Loges
Hello Loges,
Very useful article. Thankyou.
I’m looking at how to persist the changes made to the windows container. As I could not commit or checkpoint the running windows container.
Could you please help ?
hI ,
i AM GETTING THIS BELOW ERRO CAN YOU PLEASE RESOLVE THIS.
PS C:\WINDOWS\system32> docker build -t jenkins D:\jenkins
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx D:\jenkins\Dockerfile: The system cannot find the file specified.
PS C:\WINDOWS\system32> docker build -t jenkins C:\jenkins
Sending build context to Docker daemon 122.5MB
Step 1/5 : FROM microsoft/windowsservercore
—> 824f26e4c566
Step 2/5 : ADD ./setup c:/jenkins
—> Using cache
—> 67f09c2b1e55
Step 3/5 : RUN Powershell.exe -Command Install-WindowsFeature Web-Server
—> Using cache
—> e1764b74965c
Step 4/5 : RUN [“msiexec.exe”, “/i”, “D:\\jenkins\\jenkins.msi”, “/q”]
—> Running in f0750fc3adea
T h i s i n s t a l l a t i o n p a c k a g e c o u l d n o t b e o p e n e d . V e r i f y t h a t t h e p a c k a g e e x i s t s a n d t h a t y o u c a n a c c e s s i t , o r c o n t a c t t h e a p p l i c a t i o n v e n d o r t o v e r i f y t h a t t h i s i s a v a l i d W i n d o w s I n s t a l l e r p a c k a g e .
The command ‘msiexec.exe /i D:\jenkins\jenkins.msi /q’ returned a non-zero code: 1619
Hi, good blog, Just wondering how I can provide credentials to the Jenkins services.msc
Hi
thanks for the post its help me a lot 🙂
how would I provide the Jenkins service my user credentials?