Serve Static Content on a Jetty Web Server using Docker Container

Reading Time: 2 minutes

Docker is well known to containerize the application with all the necessary dependencies in order to make the application portable and deployable in a platform independent manner. And, on the other hand Jetty Server is widely used with Docker to deploy applications using war files.
But, recently I came across a requirement to expose static files and jars on a given endpoint using a Jetty Web Server within a Docker Container.
So, in this blog we’ll explore how to serve the static content on a Jetty web server from a Docker Container in few simple steps:

Copy all the required static files(static content) to a directory.

Create a Dockerfile

Here, We've used apline:latest as the base image to minimize the size of the resultant docker image, but you can use any other image of your choice.


Choose what to expose
Create an XML file to define the end point where the files will be served on the server and the Resources location where the files reside.

In the file above-
– The Context Path has been set to root, which results in serving all the files to the default path i.e, localhost:8080/
To set a custom path, Modify <Set name=”contextPath”>/</Set> with the required value.
Ex: <Set name=”contextPath”>/static/</Set>
– The tag <Set name=”resourceBase”>/jetty/static_content</Set> captures the resource location of the static content.

Ensure that this file is copied to the /jetty/webapps directory. Check for reference.
Once all the files are created, Verify that the parent directory structure is-
├── Dockerfile
├── expose_static_content.xml
└── static_content
├── hello.html
└── hello.tar.gz

Build the docker image
docker build -t “jetty-server-docker” .

Initiate a docker container
docker run -p 8080:8080 jetty-server-docker:latest

Verify the server is running
Check localhost:8080/

All the static files must be present in the context path that you have specified in the exposeJar.xml file.

You can find the source code at
That’s all for this quick session of exposing files using Jetty Server within Docker Container. Hope you liked the blog, Please leave comments for any discussion.
Thank you!!

Written by 

Neha is a Senior Software Consultant with an experience of more than 3 years. She is a Big data enthusiast and knows various programming languages including Scala and Java. She is always eager to learn new and advance concepts to expand her horizons and apply them in the project development.