Loading
Krishan Chawla

Technical Lead

Software Engineer

Automation Expert

Tech Enthusiast

  • About
  • Resume
  • Awards
  • Projects
  • Blogs
  • Contact
Krishan Chawla

Technical Lead

Software Engineer

Automation Expert

Tech Enthusiast

Download Resume

Recent Posts

  • How to Configure MySQL Master-Slave Replication for Data Redundancy and Scalability
  • Java Spring Boot Docker Deployment with Oracle Made Simple
  • Oracle XE In Docker On Windows: An Ultimate Guide
  • How to quickly Instrument JaCoCo agent with WebLogic
  • How to setup JaCoCo Code Coverage with Maven Project

Recent Comments

No comments to show.

Archives

  • March 2025
  • December 2024
  • May 2024
  • April 2024

Categories

  • Blog
  • Quick Byte
Blog Post

Java Spring Boot Docker Deployment with Oracle Made Simple

19 March, 2025 Blog, Quick Byte by Krishan Chawla
Java Spring Boot Docker Deployment with Oracle Made Simple

Table of Content

  • Introduction
  • Why Use Docker for Java Spring Boot Applications?
  • Prerequisites:
  • Step 1: Create a Simple Spring Boot Application
  • Step 2: Download and Add the Oracle JDBC Driver
  • Step 3: Create a Dockerfile
  • Step 4: Build and Run the Docker Container
  • Step 5: Run Oracle Database in a Docker Container
  • Conclusion

Introduction

In today’s DevOps-driven world, containerization has become a crucial aspect of deploying applications efficiently. Docker enables developers to package applications along with their dependencies, ensuring seamless deployment across different environments.

In this blog, we will walk through the step-by-step process of deploying a Java Spring Boot application on Docker with Oracle Database, including how to tackle the challenge of downloading the OJDBC driver, which is not available through Maven.

Why Use Docker for Java Spring Boot Applications?

  1. Consistency: Ensures the application runs the same way across different environments.
  2. Scalability: Containers can be easily scaled using tools like Kubernetes.
  3. Isolation: Each application runs in an isolated environment, avoiding dependency conflicts.
  4. Efficiency: Docker containers are lightweight and resource-efficient compared to VMs.

Prerequisites:

Before getting started, ensure you have the following installed:

  • Java JDK 17+
  • Spring Boot Application (Maven/Gradle)
  • Docker (Installed and running)
  • Oracle Database (Running in Docker or accessible remotely)
  • OJDBC Jar (Manually downloaded from Oracle website)
  • Basic knowledge of Docker and Spring Boot

Step 1: Create a Simple Spring Boot Application

If you already have a Spring Boot project, skip this step. Otherwise, create a new one using Spring Initializr:

curl https://start.spring.io/starter.zip -d dependencies=web -o demo.zip
unzip demo.zip -d demo
cd demo

Ensure your pom.xml has the following dependencies:

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

Create a simple REST controller in /src/main/java/com/example/demo/HelloController.java

@RestController
@RequestMapping(“/api”)
Public class HelloController {

	@GetMapping(“helloWorld”)
	public String sayHello() {
		return “”Hello, Dockerized Spring Boot Application!”;
	}

}

Now, build the application:

mvn clean package -DskipTests

Step 2: Download and Add the Oracle JDBC Driver

Since Oracle’s JDBC driver is not available in public Maven repositories, you must download it manually from Oracle JDBC Downloads page.

Once downloaded, add it to your local Maven repository:

mvn install:install \
	-Dfile=ojdbc8.jar \
	-DgroupId=com.oracle \
	-DartifactId=ojdbc8 \
	-Dversion=21.9.0.0 \
	-Dpackaging=jar


Then, include the dependency in your pom.xml:

<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc8</artifactId>
	<version>21.9.0.0</version>
</dependency>

Step 3: Create a Dockerfile

A Dockerfile defines the environment needed to run your application. Create a Dockerfile in the project root:

# Use an official OpenJDK runtime as base image
FROM openjdk:17-jdk-slim

# Set working directory in container
WORKDIR /app

# Copy JAR file into the container
COPY target/demo-0.0.1-SNAPSHOT.jar app.jar 

# Expose the port the app runs on
EXPOSE 8080

# Run the application
CMD [“java”, “”-jar, “app.jar”]

Step 4: Build and Run the Docker Container

Now, build your Docker image:

Docker build -t my-spring-app .

Run the container:

Docker run -d -p 8080:8080 —name spring-app my-spring-app

Verify that the application is running by opening your browser and visiting:

http://localhost:8080/api/hello

Step 5: Run Oracle Database in a Docker Container

To run an Oracle Database instance in Docker, use:

Docker run -d —name oracle-test \
	-p 1521:1521 \
	-e ORACLE_SID=ORCL \
	-e ORACLE_PBD=ORCLPDB1 \
	-e ORACLE_PWD=admin123 \
	container-registry.oracle.com/database/enterprise:latest

Update your application.properties file:

spring.datasource.url=jdbc:oracle:thin:@//oracle-db:1521/ORCLPDB1
spring.datasource.username=system
spring.datasource.password=admin123
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

Ensure both services are running on the same Docker network:

docker network create mynetwork
docker network connect mynetwork spring-app
docker network connect mynetwork oracle-db

Conclusion

By following this guide, you have successfully Dockerized a Java Spring Boot application, connected it to an Oracle database using Docker, and resolved the OJDBC download challenge.

Key Takeaways:

  • Docker ensures portability and scalability for Java applications.
  • Using Docker Compose simplifies multi-container deployment.
  • Overcoming OJDBC driver challenges is possible with manual integration.

Post Views: 17
Share:
Tags: ContainerizationDatabase IntegrationDevOpsDocker ContainerDocker DeploymentDocker for Java AppsDocker TroubleshootingJava Application DeploymentJava DevelopmentJava Spring Boot TutorialMicroservicesOJDBC DriverOracle DatabaseOracle JDBCSpring BootSpring Boot DockerSpring Boot with Oracle
Related Posts
Setup Oracle XE on Dockers
Oracle XE In Docker On Windows: An Ultimate Guide

Setting up Oracle XE in your local development environment can significantly speed up application development by giving you a powerful…

Setup Jacoco Code Coverage with Weblogic
How to quickly Instrument JaCoCo agent with WebLogic

JaCoCo is an open-source library created by the EclEmma team for measuring and reporting code coverage in an application. It…

Post navigation

Prev
Next
Write a comment Cancel Reply