Installing Tomcat Web Server through Docker File For Windows Container
In this blog, we will show you installing tomcat web server through docker file for Windows container.
REQUIREMENTS
- Windows container host with Docker service installed.
- Base windows server core image.
- JAVA & TOMCAT Installation files.
DOWNLOAD JRE SETUP FILE
- Go to the URL https://www.java.com/en/download/windows-64bit.jsp
- Click on Agree and Start Free Download to download the file.
DOWNLOAD JDK SETUP FILE
- Click on jdk8u131_windows-x64.exe link to download the JDK file.
DOWNLOAD AND CUSTOMIZE TOMCAT
- Go to the URL https://tomcat.apache.org/download-90.cgi
- Click on 64-bit Windows zip link to download the 64-bit version of tomcat.
- Extract the downloaded ZIP file apache-tomcat-9.0.0.M21-windows-x64.zip to an folder named tomcat
- Go to tomcat\conf\ folder and open web.xml file in notepad.
- To enable the directory listing, change the “listings” value from false to true
- Go to tomcat\conf\ folder and open server.xml file in notepad.
- To change the TCP Port, locate the word connector port and change the port number for your environment.
“Note: In this demo, we are using the default port for tomcat is 8080
- Go to tomcat\conf\ folder and open context.xml file in notepad.
- To Enable automatic reload after code changes, add <Context reloadable=”true”> in the context.xml file.
PREPARING ENVIRONMENT FOR BUILDING IMAGE
- Create a folder named Java under c:\ drive using below command.
New-Item -type Directory -name java -path c:
- Create a subfolder named setup under C:\java using below command
New-Item -Type Directory -Name setup -path c:\java\
- Copy the download JRE, JDK & tomcat files to C:\java\setup folder.
- Create a new file named jre.cfg in C:\java\setup folder.
- Add the below content on jre.cfg file and save it.
INSTALL_SILENT=Enable
SPONSORS=Disable
NOSTARTMENU=Enable
REBOOT=Disable
EULA=Disable
AUTO_UPDATE=Disable
STATIC=Enable
- Create a new file named jre.cmd and add the below content and save it.
pushd %~dp0
start /wait jre-8u131-windows-x64.exe INSTALLCFG=%~dp0jre.cfg
- Create a new file named jdk.cmd and paste the below content and save it.
pushd %~dp0
start /wait jdk-8u131-windows-x64.exe INSTALLCFG=%~dp0jre.cfg
- Create a new file named Environmentvariable.ps1 under C:\java\setup folder and add the below content and save it.
[Environment]::SetEnvironmentVariable(“JRE_HOME”,”C:/Program Files/Java/jre1.8.0_131″)
[Environment]::SetEnvironmentVariable(“JAVA_HOME”,”C:/Program Files/Java/jdk1.8.0_131″)
- Create a new file named tomcatservice.bat and paste the below content and save it.
cd\
cd .\tomcat\bin\
.\service.bat install
- The overall file structure of setup folder has shown below.
CREATING DOCKER FILE FOR BUILDING IMAGE
- Create a new file named dockerfile under C:\java folder using below command.
- Open the dockerfile in notepad and paste the below contents and save it.
# THIS DOCKER FILE WAS DEVELOPED BY ASSISTANZ NETWORKS
# SPECIFY THE CONTAINER IMAGE
FROM microsoft/windowsservercore
# COPY THE APACHE INSTALLATION FILES INTO THE CONTAINER
ADD ./setup c:/source
RUN powershell.exe -command \
# INSTALLING JAVA JRE
./source/jre.cmd; \
# INSTALLING JAVA JDK
./source/jdk.cmd; \
# COPYING CUSTOMIZE TOMCAT FILES TO C drive
Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; \
# SETTING UP ENVIRONMENT PATH VARIABLES FOR JRE & JDK FOLDERS
./source/Environmentvariable.ps1; \
# Installing Tomcat service
cmd.exe /c c:/source/tomcatservice.bat; \
# SET TOMCAT SERVICE TO RUN UNDER LOCAL SYSTEM ACCOUNT
sc.exe config tomcat9 obj=LocalSystem start=auto; \
# REMOVE TOMCAT SETUP FILES FROM SOURCE DIRECTORY
cmd.exe /c rd /S /Q c:\source
BUILDING THE IMAGE
- Open the PowerShell window and execute the below command to build the image.
docker build –t tomcat c:\java
It will take few minutes to complete the building process.
- The build completed successfully as shown below.
VERIFYING THE INSTALLATION
- Verify the images using docker images command.
- Launch a new container using below command.
docker run -it -p 80:8080 tomcat powershell
- Once the container has been created verify the tomcat service status using below command.
Get-Service tomcat9
- Browse the container host IP (192.168.232.80) to view the default homepage.
VIDEO
Thanks for reading this blog. We hope it was useful for you to learn how to install Tomcat web server in windows container.
Loges