πŸ”₯ Launch Offer: Interview Preparation Bundle @ β‚Ή2,499 β‚Ή9,999 β€’ 75% OFF. Offer expires in πŸ”₯ Launch Offer: Interview Preparation Bundle @ β‚Ή2,499 β‚Ή9,999 β€’ 75% OFF. Offer expires in Interview Preparation Bundle @ β‚Ή2,499 β‚Ή9,999

00:00:00 Get Bundle
home docker docker-maven-spring-boot-interview-questions-and-answers
Interview guide Docker 42 sections

Docker, Maven & Spring Boot Interview Questions and Answers

1. What is Maven? Maven is a build automation and dependency management tool for Java projects. It helps developers: Download project dependencies automatically. Compile Java source code. Run…

Start reading
By javainterviewprep June 9, 2026 8 min read

1. What is Maven?

Maven is a build automation and dependency management tool for Java projects.

It helps developers:

  • Download project dependencies automatically.
  • Compile Java source code.
  • Run unit tests.
  • Package the application into a JAR or WAR.
  • Install artifacts into the local Maven repository.
  • Support automated builds in CI/CD pipelines.

It uses a configuration file called pom.xml.


2. What is the purpose of pom.xml?

pom.xml (Project Object Model) contains all project information.

It defines:

  • Project name
  • Version
  • Dependencies
  • Plugins
  • Java version
  • Build configuration

Example:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

When Maven runs, it downloads this dependency automatically.


3. What does mvn clean do?

mvn clean deletes the previously generated build artifacts by removing the target/ directory.

This ensures that the next build starts from a clean state and avoids issues caused by stale compiled classes.


4. What does mvn compile do?

It compiles Java source files into .class files.

Example:

OrderService.java

↓

OrderService.class

The compiled files are stored in:

target/classes

No JAR is created during this phase.


5. What does mvn test do?

It executes all unit tests present under:

src/test/java

If any test fails, Maven reports a build failure and prevents later lifecycle phases from succeeding.


6. What does mvn package do?

mvn package performs:

Compile

↓

Run Tests

↓

Create Executable JAR/WAR

The generated JAR is placed inside the target/ directory.


7. What does mvn install do?

mvn install performs everything up to the package phase and then copies the generated artifact into the local Maven repository.

Example:

~/.m2/repository

This allows other local Maven projects to use the artifact as a dependency.


8. What is the difference between mvn package and mvn install?

mvn packagemvn install
Creates the JAR/WARCreates the JAR/WAR
Stores it in target/Stores it in target/ and .m2/repository
Doesn’t install locallyInstalls locally

9. Why do developers usually run mvn clean install?

Because it performs a complete fresh build.

Flow:

Delete target

↓

Compile

↓

Test

↓

Package

↓

Install

It ensures no old build artifacts interfere with the current build.


10. Where does Maven store downloaded dependencies?

Inside

~/.m2/repository

This is called the local Maven repository.

Downloaded dependencies are reused in future builds.


11. What is the target folder?

The target folder contains all generated build artifacts.

Examples:

target/

classes/

test-classes/

application.jar

reports

It is automatically created during the build.


12. What is an executable Spring Boot JAR?

An executable Spring Boot JAR contains:

  • Compiled application code
  • Spring Boot dependencies
  • Embedded Tomcat (or Jetty/Undertow)
  • Configuration files
  • Resources

It can run independently using:

java -jar application.jar

13. What does mvn spring-boot:run do?

It starts the Spring Boot application directly from the source code.

It compiles the project if necessary but does not package it into a JAR.

This command is mainly used during development.


14. What is the difference between mvn spring-boot:run and java -jar?

spring-boot:runjava -jar
Runs from source codeRuns an already-built JAR
No JAR requiredJAR is mandatory
Mostly used during developmentMostly used after packaging or deployment

15. What is Docker?

Docker is a containerization platform.

It packages an application together with:

  • Operating system libraries
  • Runtime
  • Dependencies
  • Configuration

This ensures the application behaves the same in every environment.


16. Why do we need Docker?

Without Docker:

Developer Laptop

Java 21

Ubuntu

Works

Production

Java 17

Different Linux

Fails

Docker packages everything together so that the application runs consistently everywhere.


17. What is a Dockerfile?

A Dockerfile is a text file containing instructions to build a Docker image.

Example:

FROM eclipse-temurin:21-jdk

COPY app.jar app.jar

ENTRYPOINT ["java","-jar","app.jar"]

Docker executes these instructions while building the image.


18. What does docker build do?

docker build creates a Docker image.

It:

  • Reads the Dockerfile
  • Downloads the base image if necessary
  • Copies the application files
  • Creates image layers
  • Stores startup instructions
  • Produces a Docker image

Example:

docker build -t order-service .

19. Does docker build start the application?

No.

docker build only creates a Docker image.

The application starts only when a container is created using:

docker run

20. What is a Docker Image?

A Docker image is an immutable package containing everything required to run an application.

It includes:

  • Linux filesystem
  • Java runtime
  • Application JAR
  • Libraries
  • Configuration
  • Startup command

Think of it as a blueprint.


21. What is a Docker Container?

A container is a running instance of a Docker image.

The image is static.

The container is dynamic.

Example:

Image

↓

Container

↓

Running Application

22. Can multiple containers be created from one image?

Yes.

Example:

order-service Image

↓

Container 1

↓

Container 2

↓

Container 3

Each container runs independently.


23. What does docker run do?

docker run:

  • Creates a container from an image.
  • Executes the ENTRYPOINT command.
  • Starts the application.

Example:

docker run order-service

24. What happens internally when docker run is executed?

Flow:

Find Image

↓

Create Container

↓

Execute ENTRYPOINT

↓

java -jar app.jar

↓

Spring Boot Starts

↓

Application Running

25. What is the purpose of ENTRYPOINT?

ENTRYPOINT defines the default command that runs when the container starts.

Example:

ENTRYPOINT ["java","-jar","app.jar"]

Whenever the container starts, Docker automatically executes this command.


26. What is the purpose of COPY in a Dockerfile?

COPY copies files from the host machine into the Docker image.

Example:

COPY target/app.jar app.jar

This copies the generated Spring Boot JAR into the image.


27. What is the purpose of FROM?

FROM specifies the base image.

Example:

FROM eclipse-temurin:21-jdk

Docker builds the new image on top of this base image.


28. What are Docker layers?

Each instruction in a Dockerfile creates a new layer.

Example:

FROM

↓

Layer 1

COPY

↓

Layer 2

ENTRYPOINT

↓

Layer 3

Layers are cached and reused, making future builds much faster.


29. Why is Docker build faster the second time?

Because Docker caches unchanged layers.

If only the application JAR changes, Docker reuses the base image and other unchanged layers instead of rebuilding everything.


30. Explain the complete flow from code to running application.

Write Java Code

↓

mvn clean install

↓

Creates JAR

↓

docker build

↓

Creates Docker Image

↓

docker run

↓

Creates Container

↓

Runs java -jar app.jar

↓

Spring Boot Starts

↓

Application Available

31. What is the difference between a JAR and a Docker Image?

JARDocker Image
Contains the applicationContains the application plus runtime and environment
Requires Java to be installedIncludes the required runtime/environment
Runs with java -jarRuns with docker run

32. Why is a Docker Image immutable?

A Docker image cannot be modified after it is built.

If changes are required, a new image is created.

This ensures consistency across environments.


33. Explain Docker Image vs Container using Java.

Java:

class Car {}
Car c = new Car();

Docker equivalent:

Car class

↓

Docker Image

Car Object

↓

Docker Container

The image is the blueprint, and the container is the running instance.


34. In a production environment, do we run mvn clean install on the server?

Typically, no.

A CI/CD pipeline builds the application and creates a Docker image.

The image is pushed to a container registry (such as Docker Hub or a private registry).

Production servers pull the image and run it.

Running Maven builds directly on production servers is generally avoided.


35. What is the role of Docker in CI/CD?

Typical CI/CD pipeline:

Developer Pushes Code

↓

CI Server

↓

mvn clean install

↓

docker build

↓

Push Docker Image

↓

Production Pulls Image

↓

docker run

↓

Application Running

This approach ensures that the exact same image tested in CI is deployed to production.


36. Interview Scenario: “You changed only one Java class. Will Docker rebuild everything?”

No.

Docker uses layer caching.

If the base image and Dockerfile instructions haven’t changed, Docker rebuilds only the layer affected by the updated application JAR, while reusing the cached layers for the operating system, Java runtime, and other unchanged instructions.


⭐ Frequently Asked Follow-up Questions

Q. Why do we need both Maven and Docker?

Answer:

Because they solve different problems.

  • Maven builds the application (source code β†’ executable JAR).
  • Docker packages that application together with its runtime and environment (JAR β†’ Docker image β†’ container).

Q. Can Docker build a JAR?

Answer:

Generally, no. Docker doesn’t compile Java source code by itself. In the common workflow, Maven first creates the JAR, and Docker packages it.

Note: With a multi-stage Docker build, Maven can run inside a Docker build container to compile the application, but it’s still Maven doing the compilationβ€”not Docker itself.


Q. Can we run a JAR without Docker?

Answer:

Yes.

java -jar app.jar

Docker is optional for running a Spring Boot application. It mainly provides portability, isolation, and consistency across environments.


Q. Can we run Docker without a JAR?

Answer:

For a typical Spring Boot deployment, no. The Docker image needs the application artifact (JAR/WAR) or another build process (such as a multi-stage build or buildpacks) that produces it before the application can run.


⭐ One-Liner Revision (Very Useful Before Interviews)

QuestionOne-Line Answer
What is Maven?A build and dependency management tool for Java.
What does mvn clean do?Deletes the target/ directory.
What does mvn compile do?Compiles .java files into .class files.
What does mvn package do?Creates the executable JAR/WAR.
What does mvn install do?Installs the packaged artifact into the local Maven repository.
What does mvn spring-boot:run do?Runs the application directly from source code.
What is Docker?A containerization platform for packaging and running applications consistently.
What does docker build do?Builds a Docker image from a Dockerfile.
What is a Docker image?An immutable package containing the application and everything needed to run it.
What does docker run do?Creates a container from an image and starts the application.
Image vs ContainerImage is the blueprint; container is the running instance.
Why Docker?To ensure the application behaves consistently across development, testing, and production environments.