Running Oracle database (v12,18,19) in a docker container on Ubuntu 18.04.

Clone the repository with the official Oracle docker images:

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

Install docker, download Oracle Database, put it to the directory docker-images/OracleDatabase/SingleInstance/dockerfiles/18.3.0 containing the Dockerfile and run the following commands to build and run Enterprise Edition:

cd docker-images/OracleDatabase/SingleInstance/dockerfiles/18.3.0
mv ~/Downloads/LINUX.X64_180000_db_home.zip .
# Fix a small bug in Dockerfile, see https://github.com/oracle/docker-images/issues/1468
sed -i 's/V981623-01/LINUX.X64_180000_db_home/g' Dockerfile
sudo docker build -t oracle/database:18.3.0 --build-arg DB_EDITION=EE .
sudo docker run -d -it --rm --name oracle18 oracle/database:18.3.0
sudo docker logs oracle18 --tail 100
sudo docker logs oracle18 | grep -i password

and the following commands to build and run Standard Edition 2 (it does not require V981623-01.zip):

sudo docker build -t oracle/database-se:18.3.0 --build-arg DB_EDITION=SE2 .
sudo docker run -d -it --rm --name oracle18se oracle/database-se:18.3.0
sudo docker logs oracle18se --tail 100

the first string of the docker output contains the generated password for SYS, SYSTEM and PDBADMIN.

SE2 run successfully with the following output:

...
SQL> Disconnected from Oracle Database 18c Standard Edition 2 Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
2019-03-06T12:43:19.265419+00:00
ORCLPDB1(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2019-03-06T12:43:20.130939+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
2019-03-06T12:43:20.246414+00:00
ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
   ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE

Building and running Oracle Database 12.2.0.1 Standard Edition 2:

cd docker-images/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1
mv ~/Downloads/linuxx64_12201_database.zip .
sudo docker build -t oracle/database-se:12.2.0.1 --build-arg DB_EDITION=SE2 .
sudo docker run -d -it --rm --name oracle12se oracle/database-se:12.2.0.1
sudo docker logs oracle12se --tail 100
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
2019-03-06T14:09:38.775086+00:00
ORCLPDB1(3):CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
2019-03-06T14:09:40.120128+00:00
ORCLPDB1(3):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE  '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL  SEGMENT SPACE MANAGEMENT  AUTO
ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2019-03-06T14:09:41.201288+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
   ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed:    ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE

Checking if the oracle instance is started:

sudo docker inspect oracle12se | grep IPAddress
telnet 172.17.0.2 1521
telnet 172.17.0.2 5500

Binding the container ports to the host ports:

sudo docker run -d -it --rm --name oracle12se -p 1521:1521 -p 5500:5500 oracle/database-se:12.2.0.1
sudo docker run -d -it --rm --name oracle18se -p 1521:1521 -p 5500:5500 oracle/database-se:18.3.0

Connecting with Oracle SQL Developer:

Running sqlplus with CDB in the container:

sudo docker exec -it oracle18se /bin/bash
cd /opt/oracle/product/18c/dbhome_1/bin/
export ORACLE_SID=ORCLCDB
./sqlplus sys as sysdba

SID for the pluggable DB:

export ORACLE_SID=ORCLPDB1

Running sqlplus in the container with version 12c:

sudo docker exec -it oracle12se /bin/bash
cd /opt/oracle/product/12.2.0.1/dbhome_1/bin
export ORACLE_SID=ORCLCDB
./sqlplus sys as sysdba


Making the database to be persisted over container recreation by storing the database outside of the container:

sudo useradd -d /home/oracle -m --uid 54321 oracle
sudo su - oracle
mkdir oradata18
exit
sudo docker run -d -it --rm --name oracle18se -v /home/oracle/oradata18:/opt/oracle/oradata -p 1521:1521 -p 5500:5500 oracle/database-se:18.3.0
sudo docker logs oracle18se | head | grep -i password

Finally, I run Oracle Database versions 12, 18 and 19 as follows:

sudo docker run -d -it --rm --name oracle12se -v /home/oracle/oradata12:/opt/oracle/oradata -p 1521:1521 -p 5500:5500 oracle/database-se:12.2.0.1
sudo docker run -d -it --rm --name oracle18se -v /home/oracle/oradata18:/opt/oracle/oradata -p 1521:1521 -p 5500:5500 oracle/database-se:18.3.0
sudo docker run -d -it --rm --name oracle19se -v /home/oracle/oradata19c:/opt/oracle/oradata -p 1521:1521 -p 5500:5500 oracle/database:19.2.0-ee

Multiple Oracle Database instances with 4GB memory limit can be run on the same host as follows:

sudo docker run -d -it --rm --name oracle12se -v /home/oracle/oradata12:/opt/oracle/oradata -p 1522:1521 -p 5502:5500 -m 4G oracle/database-se:12.2.0.1
sudo docker run -d -it --rm --name oracle18se -v /home/oracle/oradata18:/opt/oracle/oradata -p 1528:1521 -p 5508:5500 -m 4G oracle/database-se:18.3.0
sudo docker run -d -it --rm --name oracle19se -v /home/oracle/oradata19c:/opt/oracle/oradata -p 1529:1521 -p 5509:5500 -m 4G oracle/database:19.2.0-ee
sudo docker run -d -it --rm --name oracle18ee -v /home/oracle/oradata18ee:/opt/oracle/oradata -p 1558:1521 -p 5558:5500 -m 4G oracle/database:18.3.0ee

If you are given the following error while attempting to run docker container with the memory limit:

WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.

add the following line to /etc/default/grub (or modify existing line):

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

update grub configuration and restart the system:

sudo update-grub
sudo reboot

Links:

3 Responses to Running Oracle database (v12,18,19) in a docker container on Ubuntu 18.04.

  1. dmitriano says:

    Connecting to a docker container as root:
    sudo docker exec -u root –workdir / -ti oracle18se /bin/sh

    1. kumar says:

      Nice Post, it really helped me

  2. Luis EP says:

    Thank you very much, it has been very useful. Greetings.

Leave a Reply

Your email address will not be published. Required fields are marked *