Installing Tomcat Web Server Through Docker File For Windows Container

Installing Tomcat Web Server Through Docker File For Windows Container

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

image
  • Click on Agree and Start Free Download to download the file.
image

DOWNLOAD JDK SETUP FILE

image
  • Click on jdk8u131_windows-x64.exe link to download the JDK file.
image

DOWNLOAD AND CUSTOMIZE TOMCAT

image
  • Click on 64-bit Windows zip link to download the 64-bit version of tomcat.
image
  • Extract the downloaded ZIP file apache-tomcat-9.0.0.M21-windows-x64.zip to an folder named tomcat
image
  • Go to tomcat\conf\ folder and open web.xml file in notepad.
image
image
  • To enable the directory listing, change the “listings” value from false to true
image
  • Go to tomcat\conf\ folder and open server.xml file in notepad.
image
image
  • To change the TCP Port, locate the word connector port and change the port number for your environment.
image

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.
image
image
  • To Enable automatic reload after code changes, add <Context reloadable=”true”> in the context.xml file.
image
PREPARING ENVIRONMENT FOR BUILDING IMAGE
  • Create a folder named Java under c:\ drive using below command.

New-Item -type Directory -name java -path c:

image
  • Create a subfolder named setup under C:\java using below command

New-Item -Type Directory -Name setup -path c:\java\

image
  • Copy the download JRE, JDK & tomcat files to C:\java\setup folder.
image
  • Create a new file named jre.cfg in C:\java\setup folder.
image
  • 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

image
  • 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

image
  • 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″)

image
  • Create a new file named tomcatservice.bat and paste the below content and save it.

cd\
cd .\tomcat\bin\
.\service.bat install

image
  • The overall file structure of setup folder has shown below.
image
CREATING DOCKER FILE FOR BUILDING IMAGE
  • Create a new file named dockerfile under C:\java folder using below command.
image
  • 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

image
BUILDING THE IMAGE
  • Open the PowerShell window and execute the below command to build the image.

docker build –t tomcat c:\java

image

It will take few minutes to complete the building process.

  • The build completed successfully as shown below.
image
VERIFYING THE INSTALLATION
  • Verify the images using docker images command.
image
  • Launch a new container using below command.

docker run -it -p 80:8080 tomcat powershell

image
  • Once the container has been created verify the tomcat service status using below command.

Get-Service tomcat9

image
  • Browse the container host IP (192.168.232.80) to view the default homepage.
image
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