Skip to content

Instantly share code, notes, and snippets.

@marcwittke
Created January 10, 2023 11:49
Show Gist options
  • Save marcwittke/4ca458ba61729e53562e74cac56675c7 to your computer and use it in GitHub Desktop.
Save marcwittke/4ca458ba61729e53562e74cac56675c7 to your computer and use it in GitHub Desktop.

Oracle Database in containers

Here are the steps to get an Oracle Database 19c up and running in an OCI container. Since there are several bash scripts involved, a linux machine is advised. (while WSL may work, untested).

I ran the following on Fedora 37 with podman installed and an alias docker=podman.

1. Clone Oracle's docker-images github repo

#SSH
git clone [email protected]:oracle/docker-images.git

#HTTP
git clone https://github.com/oracle/docker-images.git

2. Download the Oracle installation archive

you'll need an Oracle Technet Account and you have to accept the small print

3. Put the downloded archive into the respective folder

└── OracleDatabase
    └── SingleInstance
        └── dockerfiles
            └── 19.3.0
                ├── checkDBStatus.sh
                ├── checkSpace.sh
                ├── Checksum.ee
                ├── Checksum.se2
                ├── configTcps.sh
                ├── createDB.sh
                ├── createObserver.sh
                ├── dbca.rsp.tmpl
                ├── db_inst.rsp
                ├── Dockerfile
                ├── installDBBinaries.sh
here ----->     ├── LINUX.X64_193000_db_home.zip  
                ├── relinkOracleBinary.sh
                ├── runOracle.sh
                ├── runUserScripts.sh
                ├── setPassword.sh
                ├── setupLinuxEnv.sh
                └── startDB.sh

4. build the image with buildContainerImage.sh

Usage:

cd OracleDatabase/SingleInstance/dockerfiles
./buildContainerImage.sh -h

Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x] [-i] [-o] [container build option]
Builds a container image for Oracle Database.

Parameters:
   -v: version to build
       Choose one of: 11.2.0.2  12.1.0.2  12.2.0.1  18.3.0  18.4.0  19.3.0  21.3.0
   -t: image_name:tag for the generated docker image
   -e: creates image based on 'Enterprise Edition'
   -s: creates image based on 'Standard Edition 2'
   -x: creates image based on 'Express Edition'
   -i: ignores the MD5 checksums
   -o: passes on container build option

* select one edition only: -e, -s, or -x

Do it for 19.3 Enterprise:

cd OracleDatabase/SingleInstance/dockerfiles
./buildContainerImage.sh -v 19.3.0 -e

takes 5-10 minutes until:

  Oracle Database container image for 'ee' version 19.3.0 is ready to be extended: 
    
    --> oracle/database:19.3.0-ee

  Build completed in 370 seconds.

Check the image:

$ podman images
REPOSITORY                                    TAG         IMAGE ID      CREATED        SIZE
localhost/oracle/database                     19.3.0-ee   d7d03bdcb7dc  5 minutes ago  6.7 GB

5. Run a new container:

this takes 15-20 min on first start, maybe you want to skip to the next chapter ;-)

podman run --name oradev \
    -p <host port>:1521 \
    -e ORACLE_SID=ORACDB \
    -e ORACLE_PDB=ORAPDB1 \
    -e ORACLE_PWD=Oracle1234 \
    -e INIT_SGA_SIZE=1536 \
    -e INIT_PGA_SIZE=1536 \
    -e ORACLE_EDITION=enterprise \
    oracle/database:19.3.0-ee

On first start, the database is created with the given parameters. This will take 15-20 minutes:

ORACLE EDITION: ENTERPRISE

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 05-JAN-2023 14:24:48

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/21145c37396a/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                05-JAN-2023 14:24:49
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/21145c37396a/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/ORACDB.
Database Information:
Global Database Name:ORACDB
System Identifier(SID):ORACDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORACDB/ORACDB.log" for further details.

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jan 5 14:38:41 2023
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> 
System altered.

SQL> 
System altered.

SQL> 
Pluggable database altered.

SQL> 
PL/SQL procedure successfully completed.

SQL> SQL> 
Session altered.

SQL> 
User created.

SQL> 
Grant succeeded.

SQL> 
Grant succeeded.

SQL> 
Grant succeeded.

SQL> 
User altered.

SQL> SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################

Obviously, waiting 15 or more minutes before each test run is no feasable solution for CI pipelines. That's why there is:

6. Bonus: Prebuilt Database

If you want to bake the database creation into the image, and move the 15-20 mins of wait time to the container image build time, you can force its creation into the build process. The advantage is that a fresh container spins up in less than a minute. But: lots of parameters will be hard coded.

Open extensions/prebuiltdb/Dockerfile and add the following line at the very end to fix a problem with docker networking

# DISABLE Out-Of-Band, since docker has problems with it
RUN echo 'DISABLE_OOB=ON' >> /opt/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora

Prebuild your db with parameters

cd OracleDatabase/SingleInstance/extensions
./buildExtensions.sh \
    -b oracle/database:19.3.0-ee \
    -t oracle-prebuilt:19.3.0 \
    -x 'prebuiltdb' \
    -o '--build-arg ORACLE_SID=ORACDB --build-arg ORACLE_PDB=ORAPDB1 --build-arg ORACLE_PWD=Oracle1234 --build-arg AUTO_MEM_CALCULATION=false --build-arg ENABLE_ARCHIVELOG=false'
Oracle Database Docker Image extended:

  --> oracle-prebuilt:19.3.0

Build completed in 859 seconds.

Run it:

podman run -d --name oradev -p 1521:1521 oracle-prebuilt:19.3.0

Connect to it:

sqlplus sys/Oracle1234@//localhost:1521/ORACDB as sysdba
sqlplus system/Oracle1234@//localhost:1521/ORACDB
sqlplus pdbadmin/Oracle1234@localhost/ORAPDB1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment