Thursday, November 14, 2024

How to install oracle database on Ubuntu system with Docker

In this tutorial, we are going to learn how to install the Oracle database on the Ubuntu system.

- Prerequisites

Docker needs to be installed on the system to verify it use the following command

docker --version

This will list the docker version installed

elint@elint:~$ docker --version
Docker version 27.0.2, build 912c1dd

- Download the Oracle docker image

Next, download or clone the oracle docker image from the repo oracle/docker-image Unzip it.

Navigate to the Oracle database docker files; in our case, it's inside /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles. Here, you can see all the dockerfiles version. Select and navigate the desired version to install

- Download the Oracle database binary file

Download the database zip file from the Oracle website This will require the Oracle login so, create the account login and download the file. Once downloaded copy that file under the Oracle database selected dockerfile version. In our case, we are using docker file version 19.3.0

The overall folder structure looks like below

- Build the Oracle docker image

Note: You need to have at least 8-15Gb storage space on your system

Navigate to the folder

cd /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0

Using the following command to build

docker build -t oracle/database:19.3.0-ee --build-arg DB_EDITION=ee .

Here oracle/database:19.3.0-ee is the image name, you can give any name

or you can use the following command

../buildContainerImage.sh -v 19.3.0 -e

-v specifies the docker image version and -e for the enterprise edition

Note: this will take some time to build the image

- Run the Oracle container

docker run --name oracle19.3c --network host -p 1521:1521 -p 5500:5500 -v /opt/oracle:/home/oracle oracle/database:19.3.0-ee

This will take some time to complete according to your system's RAM and CPU. Once completed the output looks similar as below

You can close the terminal after this.

- Start the container

To start the container run the below command

docker start oracle19.3c

oracle19.3c is the container name; you can find it using the command: docker ps -a

elint@elint:/opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0$ docker ps -a 
CONTAINER ID   IMAGE                       COMMAND                  CREATED       STATUS                 PORTS     NAMES
767c0a92e087   oracle/database:19.3.0-ee   "/bin/bash -c 'exec …"   11 days ago   Up 11 days (healthy)             oracle19.3c

This process will set the default username and password for the system user to change it, use the command

docker exec oracle19.3c ./setPassword.sh yourPassword

Where oracle19.3c is the container name

Now, login into the container

docker exec -it oracle19.3c bash

To connect to the database use the below command

sqlplus system/yourPassword@orclpdb1

Here orclpdb1 is the default database SID created

If you are having trouble running queries with sqlplus might be due to the export path issue that can resolved by exporting the environment variable. Note: enter into the container first with the command: docker exec -it oracle19.3c bash

export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

Verify the path for sqlplus

bash-4.2$ cd /opt/oracle/product/19c/dbhome_1 
bash-4.2$ ls
OPatch	 addnode     cfgtoollogs  css  data    deinstall    drdaas   has      instantclient  jdbc  ldap  md	  nls	opmn	     ord  owm	 precomp  relnotes     root.sh.old.1  runInstaller   slax      sqlplus	utl
QOpatch  assistants  clone	  ctx  dbjava  demo	    dv	     hs       inventory      jdk   lib	 mgw	  odbc	oraInst.loc  oss  perl	 racg	  root.sh      root.sh.old.2  schagent.conf  sqlj      srvm	wwg
R	 bin	     crs	  cv   dbs     diagnostics  env.ora  install  javavm	     jlib  log	 network  olap	oracore      oui  plsql  rdbms	  root.sh.old  root.sh.old.3  sdk	     sqlpatch  usm	xdk

Now you can create a new sid/database and connect to the users.

With suitable database connector; you can connect the database using the url: jdbc:oracle:thin:@127.0.0.1:1521/orclpdb1

Share:

0 comments: