Proprietary databases with docker — Oracle
Motivation
Usually to have an oracle database on windows is a pain. Some years ago, was a pain too for linux users.
Testing & Integration tests needed untouchable and ancient oracle databases.
But not it is possible to have several oracle databases in the same host just with one click with Docker and Oracle
Note
This is not illegal, because you will use the Express edition which is free:
https://www.oracle.com/database/technologies/appdev/xe.html
The Problem
Oppositely to mysql , postgress, etc oracle container is not ready to use. You should build your own image using your own oracle binaries.
In this tutorial I will show you how to download the binaries and build your oracle (Express edition) docker container step by step!!
Step1
Download the Oracle Database Linux Binary
Your first step is to download the Download the Oracle Express Edition version 18c (xe) Linux rpm from oracle.com. Oracle’s docker files do support other editions, but the Express Edition is sufficient for getting started.
In the official blog there are a couple of links:
Step2
Clone official repository on any folder. Sample: /my/git/repos/
git clone https://github.com/oracle/docker-images.git
Step3
Copy zip file from oracle download into cloned repository
- This should be the downloaded file oracle-xe-11.2.0–1.0.x86_64.rpm.zip
- Copy this file to /my/git/repos/docker-images/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2
Step4
Go to ../OracleDatabase/SingleInstance/dockerfiles and build with your version
./buildContainerImage.sh -x -i -v 11.2.0.2
You should see this success log
If no errors, you will have a new docker image: oracle/database:11.2.0.2-xe ready to use
Step5
Run. At this point I tried several ways and just this worked for me:
docker run -d --name oracle-11g \
--shm-size=1g -p 1521:1521 \
-e ORACLE_SID=XE \
-e ORACLE_PWD=changeme \
oracle/database:11.2.0.2-xe
docker logs oracle-11g -f
If no errors, go to next step.
Step 6
Wait about 5 minutes to a complete start. Log should looks like this:
ORACLE PASSWORD FOR SYS AND SYSTEM: changemeOracle Database 11g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 11g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press <Enter> to accept the defaults.
Ctrl-C will abort.Specify the HTTP port that will be used for Oracle Application Express [8080]:
Specify a port that will be used for the database listener [1521]:
Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Confirm the password:Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:Starting Oracle Net Listener...DoneConfiguring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.SQL*Plus: Release 11.2.0.2.0 Production on Mon Jul 5 21:46:57 2021Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit ProductionSQL>
PL/SQL procedure successfully completed.SQL> SQL>
Database altered.SQL>
Database altered.SQL>
Database altered.SQL>
System altered.SQL>
System altered.SQL>
System altered.SQL>
Database altered.SQL>
Database altered.SQL> SQL>
System altered.SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Current log# 5 seq# 4 mem# 0: /u01/app/oracle/oradata/XE/redo05.log
ALTER DATABASE DROP LOGFILE GROUP 1
Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/XE/onlinelog/o1_mf_1_jg6zcwgm_.log
Completed: ALTER DATABASE DROP LOGFILE GROUP 1
ALTER DATABASE DROP LOGFILE GROUP 2
Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/XE/onlinelog/o1_mf_2_jg6zcyn3_.log
Completed: ALTER DATABASE DROP LOGFILE GROUP 2
Cleared LOG_ARCHIVE_DEST_1 parameter default value
Using LOG_ARCHIVE_DEST_1 parameter default value as /u01/app/oracle/product/11.2.0/xe/dbs/arch
ALTER SYSTEM SET db_recovery_file_dest='' SCOPE=BOTH;
step 7
If your container is running without errors and your log is equal to the previous step, you can now access to your new oracle!!
I don't know why but ORACLE_SID=acme don’t works. It is Oracle :(
This is the only parameters that worked for me:
- ip: my.ip.foo.bar
- port: 1521
- user:system
- password: changeme
- sid/service_name: xe
exec scripts on init
As is usual in databases with docker, there is special folder in which you can put your ddl scripts or dump. These files will be executed at the database start
-v ./src/SqlScripts/oracle:/u01/app/oracle/scripts/startup
docker-compose
If you follow the previous steps and your oracle image is ready. Check it with this command
docker images | grep oracle
The result should be show an oracle image with this version
oracle/database : 11.2.0.2-xe
If the image exist, you could use this docker-compose to start your N oracle containers
version: '3.7'
services:
oracle_11g_db:
image: oracle/database:11.2.0.2-xe
container_name: oracle_11g_db
shm_size: 1g
ports:
- "1521:1521"
environment:
ORACLE_SID: XE
ORACLE_PWD: changeme_please
TZ: America/Lima
volumes:
- ./my-database-scripts:/u01/app/oracle/scripts/startup
networks:
- template_network
healthcheck:
test: ["CMD-SHELL", "bash /u01/app/oracle/checkDBStatus.sh"]
interval: 20s
timeout: 5s
retries: 30
Conclusion
Thanks to oracle express edition and docker, you could have a local databases on each developer machine and disposables or automated oracle databases in your testing or integration environments!!
That’s all folks