DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Fixing Common Oracle Database Problems
  • Copy SQL Execution Plan from One Database to Another in Oracle 19c
  • Exploring the New Boolean Data Type in Oracle 23c AI
  • DB2 vs. Oracle for IBM Maximo: A Comparative Analysis

Trending

  • Integrating Security as Code: A Necessity for DevSecOps
  • Medallion Architecture: Why You Need It and How To Implement It With ClickHouse
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  1. DZone
  2. Data Engineering
  3. Databases
  4. Create an Oracle Database Docker Image

Create an Oracle Database Docker Image

A senior developer gives a tutorial on running an Oracle database inside a Docker container, and connecting the two with a Red Hat middleware, JBoss Fuse.

By 
Rogerio Santos user avatar
Rogerio Santos
·
Feb. 05, 21 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
24.3K Views

Join the DZone community and get the full member experience.

Join For Free

We often need to create or run applications that rely on databases like Oracle or SQL Server. The big problem is that we are often unable to access a corporate server for our tests. Another problem is that third parties' actions in a shared database can affect our tests or development. For these scenarios, using a Docker image is a great ally, as we can have an exclusive bank available for our development activities.

In this tutorial, we will:

  • Create a docker image for Oracle Database.
  • Connect them using Red Hat JBoss Fuse.
  • Perform a SELECT and INSERT. 

Let's start

Prepare the Container

Firstly, download or clone the files of the repository: https://github.com/oracle/docker-images/.

The second thing to do is download the binary files for the Oracle Database version of your choice. I will use version 19.3.0 for Linux. The link to download is: https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

After downloading the file (in my case, LINUX.X64_193000_db_home.zip), we need to copy it to the folder referring to the oracle version in the cloned folder. In this case, 19.3.0:

Shell
 




xxxxxxxxxx
1


 
1
$ cp ~/Download/LINUX.X64_193000_db_home.zip ./docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0/


The third step is to build the image. Go to the folder with the Docker files in the cloned project (one level before the versions folder). To build the image, we will use the below script:

Java
 




xxxxxxxxxx
1


 
1
$ ./docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0/buildDockerImage.sh -v 19.3.0 -e


If all goes well, we will have the image created. To confirm this, run the below command:

Java
 




xxxxxxxxxx
1


 
1
$ docker images
2
REPOSITORY                                TAG           IMAGE ID       CREATED          SIZE
3
oracle/database                           19.3.0-ee     d8be8934332d   53 minutes ago   6.54GB


Now, we can run our database. For this, use the below command: 

Shell
 




x



1
docker run
docker run --name myOracle1930 \
2
 -p 1521:1521 \
3
 -p 5500:5500 \
4
 -e ORACLE_SID=ORCLCDB \
5
 -e ORACLE_PDB=ORCLPDB1 \
6
 -e ORACLE_PWD=root \
7
 -e INIT_SGA_SIZE=1024 \
8
 -e INIT_PGA_SIZE=1024 \
9
 -e ORACLE_CHARACTERSET=AL32UTF8 \
10
 oracle/database:19.3.0-ee



When the container I ready, you can use the Enterprise Manager to verify it. Use port 5500 to access. In this case, https://127.0.0.1:5500/em. Use the username "system" and the password entered in the ORACLE_PWD property.

From this point, we have a Docker container running an Oracle Database, and we can connect it using any database tool like Oracle  SQL Developer, DBeaver Community, or creating a JDBC connection.

Connect Them in the Container

For this step, I will use a Red Hat JBoss Fuse 7.8 application, and I will perform queries using the component camel-sql.

The application I created is available on GitHub at https://github.com/iam-roger-io/fuse-oracle-example. Download the version from the branch called fuse78-camel-sql.

Basically, we need to create a data source. 

Java
 




x


 
1
    @Bean(name = "oracleDS")
2
    public DataSource dataSource() {             
3
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
4
        dataSource.setUrl("jdbc:oracle:thin:@172.17.0.1:1521/ORCLCDB");
5
        dataSource.setUsername("camel");
6
        dataSource.setPassword("1qaz@WSX");
7
        return dataSource;
8
    }
9
}


Notice that the IP address is the Docker IP and the SID is the name used "docker run .."

We need to create the username and password using a SQL tool. The default username, "system," doesn't has privileges for insert, only SELECT queries.

Before we do this, create a table called "person" in Oracle.

PLSQL
 




xxxxxxxxxx
1


 
1
CREATE TABLE PERSON
2
(
3
  ID NUMBER(*, 0) NOT NULL 
4
, NAME VARCHAR2(50 BYTE) NOT NULL 
5
, CONSTRAINT PERSON_PK PRIMARY KEY 
6
  (
7
    ID 
8
  )
9
)


After the table is created, create the user "camel" like below. 

PLSQL
 




xxxxxxxxxx
1
15


 
1
alter session set "_ORACLE_SCRIPT"=true;
2

          
3
create user camel identified by "1qaz@WSX"
4

          
5
GRANT create session TO camel; 
6

          
7
GRANT
8
  SELECT,
9
  INSERT,
10
  UPDATE,
11
  DELETE
12
ON
13
  sys.person
14
TO
15
  camel;


In the project POM file, I set the dependency for the JDBC driver as ojdbc8. 

XML
 




x


 
1
        <dependency>
2
            <groupId>com.oracle.database.jdbc</groupId>
3
            <artifactId>ojdbc8</artifactId>
4
        </dependency>    


It is recommended to use the Oracle BOM mechanism. Notice in the pom.xml file that there are two BOM definitions. One definition for Fuse 78 and a second definition for Oracle JDBC.

XML
 




x


 
1
    <dependencyManagement>
2
        <dependencies>
3
            <dependency>
4
                <groupId>org.jboss.redhat-fuse</groupId>
5
                <artifactId>fuse-springboot-bom</artifactId>
6
                <version>7.8.0.fuse-sb2-780038-redhat-00001</version>
7
                <type>pom</type>
8
                <scope>import</scope>
9
            </dependency>
10
            
11
            <dependency>
12
              <groupId>com.oracle.database.jdbc</groupId>
13
               <artifactId>ojdbc-bom</artifactId>
14
               <version>21.1.0.0</version>
15
               <type>pom</type>
16
               <scope>import</scope>
17
             </dependency>          
18
            
19
        </dependencies>
20
    </dependencyManagement>


In the project, one route performs select all registers in the Oracle Database and, in sequence, insert a new register.

Java
 




xxxxxxxxxx
1
33


 
1
@Component
2

          
3
public class Routes  extends RouteBuilder {  
4

          
5
    @Override
6
    public void configure() throws Exception {            
7

          
8
         from("timer://foo?fixedRate=true&period=1000")
9
        .toD("sql://SELECT * FROM SYS.PERSON?dataSource=#oracleDS")
10
        .log("### NUMBER OF RECORDS IN  THE TABLE PERSON : ${body.size}")
11

          
12
        .process(new Processor() {            
13

          
14
            @Override
15
            public void process(Exchange exchange) throws Exception {
16
              
17
                @SuppressWarnings("unchecked")
18
                List<Object> id =  exchange.getIn().getBody(List.class);
19
                Integer number = id.size()+1;
20
                String name = " Person " +number;                  
21

          
22
                exchange.getIn().setHeader("personId", number);
23
                exchange.getIn().setHeader("personName", name);              
24

          
25
            }
26
        })       
27

          
28
        .toD("sql://INSERT INTO SYS.PERSON (ID, NAME) VALUES (:#personId, :#personName)?dataSource=#oracleDS")
29

          
30
        .log("### INSERTED NEW RECORD IN THE TABLE PERSON ${header.personName}");
31

          
32
    }
33
}


And that's all folks, run the application and notice its behavior. It is the same for Oracle in Docker or traditional installations; however, for us developers, the capacity of reproducing a complex database like an Oracle database in a simple container is a great facility.

Database Oracle Database Docker (software)

Opinions expressed by DZone contributors are their own.

Related

  • Fixing Common Oracle Database Problems
  • Copy SQL Execution Plan from One Database to Another in Oracle 19c
  • Exploring the New Boolean Data Type in Oracle 23c AI
  • DB2 vs. Oracle for IBM Maximo: A Comparative Analysis

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!