×
Installing Tomcat Web Server through Docker File For Windows Container
Blog Containers

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.

19 thoughts on “Installing Tomcat Web Server through Docker File For Windows Container”

  1. Hi pal,

    I have followed your steps, It looks good, but I have a small doubt.

    I am using Windows server 2016 docker & built tomcat image
    while accessing tomcat from windows server, ip:80 ( I cant access the page)
    by using docker container ip, ip:8080 ( i can access the tomcat page)

    Can you give your comments

    Regards
    Sai Krishna
    saikrishna2733@gmail.com

  2. Hi Sai,

    Thanks for your comment. Make sure you try to access the windows server IP from another machine in your network. You will not able to access it from the container host machine.

  3. your tutorial does fail in dockerfile.
    with error at step1
    FROM needs one or three arguments issue

    i’m using a latest docker for windows (vm for docker)

    i worked with apache jena (works like charm) but apache tomcat looks very old and not even a proper working docker image (not able to make a customized username and password)(and container creation for such images is hell)

  4. Thanks for your article. I’m trying to follow it to build Java8, Tomcat9, and amazonlinux into an image to do
    some testing. In Powershell, I put the files into C:\java\setup, put the dockerfile in c:\java, and ran:
    > docker build -tag tomcat c:\java, and my current dir was c:\java.

    I got:

    >docker build –tag tomcat c:\java
    Sending build context to Docker daemon 227.6MB
    [WARNING]: Empty continuation line found in:
    RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:\source
    [WARNING]: Empty continuation lines will become errors in a future release.
    Step 1/3 : FROM amazonlinux
    —> 3faa54d46dec
    Step 2/3 : ADD ./setup c:/source
    —> Using cache
    —> 422a5c4d98fa
    Step 3/3 : RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:\source
    —> Running in 514eff32438f
    /bin/sh: powershell.exe: command not found
    /bin/sh: ./source/jdk.cmd: No such file or directory
    /bin/sh: Copy-Item: command not found
    /bin/sh: ./source/Environmentvariable.ps1: No such file or directory
    /bin/sh: cmd.exe: command not found
    /bin/sh: sc.exe: command not found
    /bin/sh: cmd.exe: command not found
    The command ‘/bin/sh -c powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:\source’ returned a non-zero code: 127

    I have Windows 10, python 3.6.4, Java 8.1_6_1.

    Thanks…..

  5. Hi Tom,

    Thanks for contacting us. I think you are trying to build Linux container image using windows 10. You need to change commands to according to that. What is the base image which you are using from your end?

    Regards,
    Loges

  6. Hello,

    Thanks. I could build my first windows docker image thanks to you.

    I have a suggestion to improve this tutorial :
    Jdk installs a jre by default so there is no need to install a jre. It should reduce image size and build time a bit.

    Regards

  7. Hello,

    I followed the same steps as mentioned.
    I am able to see that my tomcat service is up in container but I am not able to access the tomcat via container ip, ip:8080 ( i can not access the tomcat page , getting Gateway Timeout error) from container host machine.
    Can you please tell me what can be the issue.

  8. Hi Shivani,

    You have to use the container host IP with your customized port to view the Tomcat homepage.

    Regards,
    Loges

  9. Hi,

    I have Java 8 and Tomcat 8.5 already installed in my machine. Do I again need to install Java 8 the way you have mentioned? Is it possible to copy the java/tomcat folders?

    Chinmoy

  10. Hello,

    If I want to look at the tomcat log files or any errors, where I would I be looking for it?

    Thanks
    Prab

  11. I ran the docker build, but it gets stuck for a long time in this step
    C:\source>start /wait jre-8u181-windows-x64.exe INSTALLCFG=C:\source\jre.cfg

  12. Hello,
    I am using docker build –tag tomcat c:/java command in windows 10 powershell as mentioned in this site however getting the below error can any one help in this

    “docker build” requires exactly 1 argument.
    See ‘docker build –help’.

    Usage: docker build [OPTIONS] PATH | URL | –

    Build an image from a Dockerfile

  13. Will this work in Windows10 workstation? I followed all the steps and I tried alternative ways, but it doesn’t install the JRE and JDK. Any help appreciated. Thank you.

  14. C:\Users\root>docker build -t tomcat c:\java
    Sending build context to Docker daemon 301.4MB
    [WARNING]: Empty continuation line found in:
    RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:\source
    [WARNING]: Empty continuation lines will become errors in a future release.
    Step 1/3 : FROM microsoft/windowsservercore
    —> db8182d67b6c
    Step 2/3 : ADD ./setup c:/source
    —> d425b26c2591
    Step 3/3 : RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/source/tomcat -Destination c:/tomcat -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:\source
    —> Running in 15f185c70caf
    container 15f185c70caf2d346f36fed6af0c933e57d15353a66b6c953cdcdd751627ae97 encountered an error during CreateContainer: failure in a Windows system call: No hypervisor is present on this system. (0xc0351000) extra info: {“SystemType”:”Container”,”Name”:”15f185c70caf2d346f36fed6af0c933e57d15353a66b6c953cdcdd751627ae97″,”Owner”:”docker”,”IgnoreFlushesDuringBoot”:true,”LayerFolderPath”:”C:\\ProgramData\\Docker\\windowsfilter\\15f185c70caf2d346f36fed6af0c933e57d15353a66b6c953cdcdd751627ae97″,”Layers”:[{“ID”:”b3429f20-d4e3-5b0c-9ba2-eb46200851f9″,”Path”:”C:\\ProgramData\\Docker\\windowsfilter\\acbf7b70fc50525340a98c7bc1309f6048ef2f1ec5afafb62e7a0a54f9c2005c”},{“ID”:”f3ccc5bd-5a8b-526d-8ea0-6c33ed29474a”,”Path”:”C:\\ProgramData\\Docker\\windowsfilter\\12d0cada551e66863eda104ce308f7c6a461923efea2977b7fc97b301c26ddd3″},{“ID”:”cf048a94-08fd-5116-998c-83288f9e9530″,”Path”:”C:\\ProgramData\\Docker\\windowsfilter\\e41967b31f94cf969dcfe6b1d7e6a5082610ef1318d09ca3e16b2c2ca35df03b”}],”HostName”:”15f185c70caf”,”HvPartition”:true,”EndpointList”:[“a0bbdf01-76a9-458f-9d03-1941730cd749″],”HvRuntime”:{“ImagePath”:”C:\\ProgramData\\Docker\\windowsfilter\\12d0cada551e66863eda104ce308f7c6a461923efea2977b7fc97b301c26ddd3\\UtilityVM”},”AllowUnqualifiedDNSQuery”:true}

  15. “docker build” requires exactly 1 argument.
    See ‘docker build –help’.

    This is caused by cutting and pasting the command
    docker build –t tomcat c:\java
    If you type it it works. I thnk it is the –t should be -t.

  16. Followed the above mentioned steps but it is stuck at running the powershell step. Please see below for more details. Any help is really appreciated.
    C:\xxx\docker>docker build -t tomcat c:\xxx\docker
    Sending build context to Docker daemon 715.1MB
    [WARNING]: Empty continuation line found in:
    RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/xxx/docker/source/apache-tomcat-9.0.14 -Destination c:/xxx/docker/apache-tomcat-9.0.14 -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/xxx/docker/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:/xxx/docker/source
    [WARNING]: Empty continuation lines will become errors in a future release.
    Step 1/3 : FROM local:ms_windowsservercore
    —> ea9f7aa13d03
    Step 2/3 : ADD ./setup c:/xxx/docker/source
    —> 6fb4e05bf5f3
    Step 3/3 : RUN powershell.exe -command ./source/jre.cmd; ./source/jdk.cmd; Copy-Item c:/xxx/docker/source/apache-tomcat-9.0.14 -Destination c:/xxx/docker/apache-tomcat-9.0.14 -Recurse; ./source/Environmentvariable.ps1; cmd.exe /c c:/xxx/docker/source/tomcatservice.bat; sc.exe config tomcat9 obj=LocalSystem start=auto; cmd.exe /c rd /S /Q c:/xxx/docker/source
    —> Running in 7b6ea6c1ae2f

    C:\xxx>docker version
    Client: Docker Engine – Community
    Version: 18.09.1
    API version: 1.39
    Go version: go1.10.6
    Git commit: 4c52b90
    Built: Wed Jan 9 19:34:26 2019
    OS/Arch: windows/amd64
    Experimental: false

    Server: Docker Engine – Community
    Engine:
    Version: 18.09.1
    API version: 1.39 (minimum version 1.24)
    Go version: go1.10.6
    Git commit: 4c52b90
    Built: Wed Jan 9 19:50:10 2019
    OS/Arch: windows/amd64
    Experimental: false

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.