Category: java
What is Docker?
Published on 13 Aug 2026
Explanation
Docker is a containerization platform that packages an application together with its runtime dependencies. Containers provide consistent environments across development, testing, and production systems.
Code:
Application
+ Java
+ Dependencies
+ Configuration
β
Docker Image
β
Container
Explanation
A Docker image is a read-only template containing the application and its dependencies. A container is a running instance created from that image.
Code:
docker build -t student-api . docker run -p 8080:8080 student-api
Explanation
A Dockerfile contains instructions for building a Docker image. For a Spring Boot application, it can copy the generated JAR and define Java as the runtime environment.
Code:
FROM eclipse-temurin:21-jre WORKDIR /app COPY target/student-api.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]
Explanation
After creating the Dockerfile, use docker build to create an image. The image can then be executed as a container on any machine with Docker installed.
Code:
mvn clean package docker build -t student-api:1.0 . docker images
Explanation
Docker containers can expose application ports to the host machine. Port mapping allows clients to access the Spring Boot REST API running inside the container.
Code:
docker run -d \ --name student-api \ -p 8080:8080 \ student-api:1.0