Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

JSP and Servlets
  • Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
  • Set Up Tomcat 11 and a Maven Web Project in IntelliJ IDEA
  • The Servlet Request Lifecycle: @WebServlet, web.xml, init, doGet and destroy
  • Servlet Request Parameters, and Forward vs Redirect
  • Run a Java Web App in Docker: Tomcat 11 With One Compose Command
  • Sessions, Cookies and Filters in Java Servlets: Log In Once, Stay Logged In
  • Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
  • JSP Scripting: Expressions, Scriptlets, Declarations, Comments and Includes
  • JavaBeans and JSP Scopes: Page, Request, Session and Application
  • JSP Expression Language Step by Step: ${...} for Beans, Maps, Lists, Params and Scopes
  • JSTL Core Tags: c:set, c:out, c:if, c:choose and c:forEach
  • JSTL Functions and Formatting: fn:length, fn:toUpperCase, fn:contains, fmt:formatNumber and fmt:formatDate
  • Maintaining and Migrating Legacy JSP With AI: Explain the Page, Refactor to a DAO, Servlet and JSTL, Then Move It to React
  • MVC and the Front Controller With Servlets and JSP
  • Forms With JSP and Servlets: Handle the POST and Validate on the Server
  • Mini App With Servlets and JSP: Login, Logout and a Shared Web Template
  • SQLite and a JDBC Connection Pool in a Java Web App
  • Users CRUD With Servlets and JSP, Part 1: Add and List Through a DAO
  • Users CRUD With Servlets and JSP, Part 2: Update and Delete
  1. Blog
  2. /
  3. JSP and Servlets
  4. /
  5. Servlets

Run a Java Web App in Docker: Tomcat 11 With One Compose Command

Run a servlet project without installing Tomcat: one docker compose command builds the WAR with Maven on Java 25, starts Tomcat 11 in a container, and serves the app on localhost:8090.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Servlets

What you will learn

  • Install Docker Desktop, or Docker on Linux with one command
  • Build and start a servlet project with docker compose up --build -d
  • Read a two-stage Dockerfile that builds a WAR with Maven and runs it on Tomcat 11
  • Open, stop and clean up the container

Before you start

  • Servlet Request Parameters, and Forward vs Redirect
  • Opening a terminal in a project folder

Every project in this part of the course ships with three extra files: a Dockerfile, a compose.yaml and a .dockerignore. With Docker installed, you can run any of them with one command, with no Tomcat, no WildFly and no server setup on your own machine. We won't go deep into Docker here; the goal is to install it and run a project.

Step 1: get Docker

Instead of searching around, ask an AI assistant: "Create a table with the installation command for Docker on Linux and on macOS, and give me the link of Docker Desktop."

  • On Linux (Ubuntu, for example) you get one command to run in a terminal.
  • On Windows or a Mac the answer is Docker Desktop. Check the address bar says docker.com/products/docker-desktop, the official page, click Download Docker Desktop and pick the row for your machine. Most Windows PCs take Windows AMD64.

Run the installer like any other program, then restart your computer.

Step 2: open the project

Open the project from the forward and redirect lesson in IntelliJ IDEA (or any IDE). Next to pom.xml and src you'll find the three Docker files, and a README.txt with the command to run.

Step 3: run it

Open the terminal at the bottom of the IDE. Command Prompt or PowerShell both work, and the terminal opens inside the project folder. Run:

docker compose up --build -d

Docker reads the compose file, follows the Dockerfile and builds the project. The first build takes a while; later builds are much faster. When it finishes, the image is built, a network is created and the container is started.

What the files do

The Dockerfile has two stages:

# ---- build: compile the WAR with Maven on Java 25 ----
FROM maven:3.9-eclipse-temurin-25 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn -B -q dependency:go-offline
COPY src ./src
RUN mvn -B -q package -DskipTests

# ---- run: Tomcat 11 (Jakarta Servlet 6.1) on Java 25, app at / ----
FROM tomcat:11.0-jdk25-temurin
RUN rm -rf /usr/local/tomcat/webapps/*
COPY --from=build /app/target/request-dispatch.war /usr/local/tomcat/webapps/ROOT.war
EXPOSE 8080
CMD ["catalina.sh", "run"]
  • The build stage uses Maven on Java 25 to compile the project into request-dispatch.war. Copying pom.xml first and downloading dependencies before copying src lets Docker reuse that layer when only your code changes.
  • The run stage starts from a Tomcat 11 image, empties webapps, and copies the war in as ROOT.war. That's why the app opens at the root, with no context path.

The compose file connects the ports:

name: s01l05
services:
  app:
    build: .
    ports:
      - "${PORT:-8090}:8080"

Port 8090 on your computer goes to port 8080 inside the container. If 8090 is busy, set PORT first, for example in PowerShell: $env:PORT=8091; docker compose up --build -d.

The build stage, Maven on Java 25, turns pom.xml and src into request-dispatch.war. The run stage, Tomcat 11, receives it as ROOT.war. The browser on localhost:8090 reaches port 8080 inside the container. build stage maven, Java 25 mvn package run stage (container) Tomcat 11, port 8080 webapps/ROOT.war Browser localhost:8090 .war 8090:8080 Only the run stage ends up in the final image.
Two stages: Maven builds the war, Tomcat runs it. Compose maps your port 8090 to the container's 8080.

Step 4: check it in Docker Desktop

Open Docker Desktop. If it says Waiting for the Docker Engine, give it a few seconds; if it stays stuck, or Docker acts up right after the install, restart your computer. Under Containers you'll see the project, s01l05, with the container app-1 and a green dot. The port column shows 8090:8080; click it.

Step 5: open it in the browser

The browser opens localhost:8090 with the project's links. Click greet: the page at /greet says "Hello, null", because no name was passed. The servlet in this copy of the project reads a parameter called name2, so add ?name2=chaand in the address bar and the page says "Hello, chaand". It works exactly like the app did on a local Tomcat.

Step 6: stop and clean up

docker compose down

Run it in the same folder, or click the stop button on the project in Docker Desktop. You can also delete the container there for a clean start next time.

Common mistakes

  • Running the command outside the project folder. Compose looks for compose.yaml in the current folder.
  • Opening localhost:8080. Inside the container Tomcat listens on 8080, but on your machine the app is on 8090.
  • Looking for a context path such as /request-dispatch. The war is deployed as ROOT.war, so the app sits at /.
  • Forgetting to restart after installing Docker Desktop. The engine often won't start until you do.

Quick recap

Command or fileJob
docker compose up --build -dBuild the image and start the container in the background
DockerfileMaven builds the war, Tomcat 11 runs it as ROOT.war
compose.yamlMaps port 8090 on your machine to 8080 in the container
docker compose downStop and remove the container

For Docker's own ideas (images, containers and volumes) in more depth, see Docker essentials: images, containers and volumes.

Keep going in JSP and Servlets · 5 of 19

Previous
Servlet Request Parameters, and Forward vs Redirect
Next post
Sessions, Cookies and Filters in Java Servlets: Log In Once, Stay Logged In
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet

A JSP looks like HTML with a little Java, yet Tomcat runs it as a servlet. See what a servlet container does for each request, what the generated hello_jsp.java looks like, what a .war holds, and Tomcat vs TomEE.

Set Up Tomcat 11 and a Maven Web Project in IntelliJ IDEA

Set JAVA_HOME, install Tomcat 11 on a free port, create a Jakarta EE web application with Maven in IntelliJ IDEA, read its folders and pom.xml, and run it on Tomcat.

The Servlet Request Lifecycle: @WebServlet, web.xml, init, doGet and destroy

A servlet is a Java class that answers a URL. Follow one request through Tomcat, map servlets with @WebServlet and web.xml, build a page from a list, and watch init, doGet and destroy run.

Servlet Request Parameters, and Forward vs Redirect

Read ?name=Emma with getParameter, then hand a request on two ways: a forward keeps one request and its attributes, a redirect makes the browser ask again and the attribute is gone.

On this page

  • Step 1: get Docker
  • Step 2: open the project
  • Step 3: run it
  • What the files do
  • Step 4: check it in Docker Desktop
  • Step 5: open it in the browser
  • Step 6: stop and clean up
  • Common mistakes
  • Quick recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.