DevOps Series: Running Oracle Database 19C in a Docker Container
Introduction
In this article, we will learn the prerequisites to install Docker follows with Docker installation and then using Docker container we will see how to run the database on it along with the listener.
In our environment, we have used Linux 7.5 and Docker version as 1.23.1. We just need a very lightweight Linux machine to use the Docker.
First, we are going to install the Docker engine and Docker compose.
i) Install Docker Engine:
sudo yum install docker-engine -y
sudo yum install docker-engine -y
Before installing Docker Engine, ensure to make changes in your public-yum-ol7.repo file as mentioned by, A Simple Guide to docker installation on Oracle Linux 7.5, Puneeth Prakash ( https://blogs.oracle.com/blogbypuneeth/a-simple-guide-to-docker-installation-on-oracle-linux-75)
ii) Start Docker:
sudo service docker start
sudo service docker start
# docker — version
Docker version 18.09.1-ol, build c3ab8a8
Docker version 18.09.1-ol, build c3ab8a8
iii) Install Docker-compose:
Docker Compose is a tool that allows you to define and run multi-container Docker applications. Start by downloading the Docker Compose binary into the /usr/local/bin directory using the
# sudo curl -L “https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 791 0 — : — : — — : — : — — : — : — 792
100 11.1M 100 11.1M 0 0 842k 0 0:00:13 0:00:13 — : — : — 930kOnce the download is complete, make the binary executable by typing:
# sudo chmod +x /usr/local/bin/docker-compose
You have new mail in /var/spool/mail/root
To verify the installation type the following command to print the Compose version:
# docker-compose — version
docker-compose version 1.23.1, build b02f1306
# docker-compose — version
docker-compose version 1.23.1, build b02f1306
# service docker status
Redirecting to /bin/systemctl status docker.service
● docker.service — Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/docker.service.d
└─docker-sysconfig.conf
Active: active (running) since Tue 2019–09–10 18:49:30 AEST; 11min ago
Docs: https://docs.docker.com
Main PID: 3706 (dockerd)
Memory: 101.5M
CGroup: /system.slice/docker.service
└─3706 /usr/bin/dockerd — selinux-enabled — insecure-registry 172.30.0.0/16 — storage-driver devicemapper -…Sep 10 18:49:01 opsdev.localdomain dockerd[3706]: time=”2019–09– —
Sep 10 18:49:30 opsdev.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
iv) A new Unix group docker was created during installation. Adding oracle user to Docker group.
# usermod -a -G docker oracle
# id oracle
uid=600(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba),54327(asmdba),982(vboxsf),976(docker)
For this article, I am going to pull a docker image with Oracle version 19.3.0 which I already built based on Oracle 19.3.0 Enterprise Edition. I am using that for my testing. Please use as of your licence requirements.
V) Connect to the docker hub
# docker login -u banglamon
Password: xxxxx
Login Succeeded
Password: xxxxx
Login Succeeded
If you don’t have any account then you can sign up for an account on https://hub.docker.com/.
Vi) Pull image from the docker hub
# docker pull banglamon/oracle193db:19.3.0-ee
Trying to pull repository docker.io/banglamon/oracle193db …
19.3.0-ee: Pulling from docker.io/banglamon/oracle193db
ad18637d63f5: Pull complete
4aebb26cf7d5: Pull complete
30325de6313a: Pull complete
17163f94892b: Pull complete
ae28d7c83673: Pull complete
e925f4d276bf: Pull complete
Digest:sha256:2afff2ab1a5ecd7f40767a39398b3e7598bab92ff68793d81699c6ea0008f04f
Status: Downloaded newer image for banglamon/oracle193db:19.3.0-ee
VII) Validate docker image for the Oracle Database
# docker image ls|grep oracle
VIII) Setup Oracle database as a container
At this stage, we have a docker image ready and did not set up any container yet. Let’s set up first Oracle 19c Database container named “oracle19db”
# docker run -d — name 19.3.0-ee -p 1521:1521 -p 8081:8081 -e ORACLE_SID=MORAL -e ORACLE_PDB=MORALPDB -e ORACLE_PWD=Oracle123 -v /u01/app/oracle/oradata:/opt/oracle/oradata banglamon/oracle193db:19.3.0-ee
where,
-d To start a container in detached mode, you use -d=true or just -d option
-p Mapped port 1521 and 8081 on my laptop to the corresponding ports inside the container
-e env list Set environment variables
-v Mapped my local directory (/u01/app/oracle/oradata ) to the default location where the data files will be stored (:/opt/oracle/oradata) to ensure the files are persisted outside my container.
-p Mapped port 1521 and 8081 on my laptop to the corresponding ports inside the container
-e env list Set environment variables
-v Mapped my local directory (/u01/app/oracle/oradata ) to the default location where the data files will be stored (:/opt/oracle/oradata) to ensure the files are persisted outside my container.
# docker ps -a | grep oracle
4541cab89244 banglamon/oracle193db:19.3.0-ee “/bin/sh -c ‘exec $O…” 2 minutes ago Up 2 minutes (health: starting) 0.0.0.0:1521->1521/tcp, 0.0.0.0:8081->8081/tcp, 5500/tcp 19.3.0-ee
Though it is showing container is up and healthy but it is not ready yet.
IV) Checking log information
As I am running container in background — checking progress log using below command.
X) Database Connection:
Connect to the database container “oracle19db”—
# docker exec -it oracle19db bash -c “source /home/oracle/.bashrc; sqlplus /nolog”SQL*Plus: Release 19.0.0.0.0 — Production on Tue Sep 10 11:05:42 2019
Version 19.3.0.0.0Copyright © 1982, 2019, Oracle. All rights reserved.
Some testing to the database level
SQL> conn / as sysdba
Connected.
SQL> select name from v$database;
NAME
— — — —
MORAL
SQL> show con_name
CON_NAME
— — — — — — — — — — — — — — —
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
2 PDB$SEED READ ONLY NO
3 MORALPDB READ WRITE NO
SQL> alter session set container=MORALPDB;
Session altered.
SQL> create table DockerTst (id int,name varchar2(20));
Table created.
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
— — — — — — — — — — — — — — —
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL> select name from v$datafile;
NAME
— — — — — — — — — — — — — — — — — — — — — — — — — — -
/u01/app/oracle/oradata/MORAL/system01.dbf
/u01/app/oracle/oradata/MORAL/sysaux01.dbf
/u01/app/oracle/oradata/MORAL/undotbs01.dbf
/u01/app/oracle/oradata/MORAL/pdbseed/system01.dbf
/u01/app/oracle/oradata/MORAL/pdbseed/sysaux01.dbf
/u01/app/oracle/oradata/MORAL/users01.dbf
/u01/app/oracle/oradata/MORAL/pdbseed/undotbs01.dbf
/u01/app/oracle/oradata/MORAL/MORALPDB/system01.dbf
/u01/app/oracle/oradata/MORAL/MORALPDB/sysaux01.dbf
/u01/app/oracle/oradata/MORAL/MORALPDB/undotbs01.dbf
/u01/app/oracle/oradata/MORAL/MORALPDB/users01.dbf
11 rows selected.
SQL> create tablespace testdocker datafile ‘/u01/app/oracle/oradata/MORAL/testdocker01.dbf’ size 100M;
Tablespace created.
Note: Using the same image we can deploy multiple containers with quick provisioning.
XI) To stop container we can execute below command —
# docker ps -a | grep oracle
54c750349cbd oracle/database:19.3.0-ee “/bin/sh -c ‘exec $O…” About an hour ago Up About an hour (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:8081->8081/tcp, 5500/tcp oracle19db
54c750349cbd oracle/database:19.3.0-ee “/bin/sh -c ‘exec $O…” About an hour ago Up About an hour (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:8081->8081/tcp, 5500/tcp oracle19db
By default, Docker process waits for 10 seconds to stop a container and then kills it. We can execute Docker wait with passing time value in seconds as below -
# docker stop -t 50 oracle19db
oracle19db
oracle19db
# docker ps -a | grep oracle
54c750349cbd oracle/database:19.3.0-ee “/bin/sh -c ‘exec $O…” About an hour ago Exited (143) 6 seconds ago oracle19db
54c750349cbd oracle/database:19.3.0-ee “/bin/sh -c ‘exec $O…” About an hour ago Exited (143) 6 seconds ago oracle19db
XII) Play with Docker commands
To start the container again —
# docker start oracle19db
oracle19db
oracle19db
To get the container size and consumed OS resources —
To rename a container —
# docker rename oracle19db oracle19test
To remove a container , we need use below command —
# docker rm -f 54c750349cbd
Summary
In this article we have seen how to Install docker and how to use it and then we have used Docker container to create the Oracle 19c Database and explored various commands with docker.
Appendix
Currently there is an official docker image (Oracle Database Server 12.2.0.1 Docker Image)is available link of Oracle Docker Container
To download that, you need to create an account and accept the license [ORACLE]
========================================
docker login -u asiandevs@gmail.com -p XXXXXX container-registry.oracle.com
[oracle@oel75 ~]$ docker login -u monowar.mukul@gmail.com -p XXXX container-registry.oracle.com
========================================
docker login -u asiandevs@gmail.com -p XXXXXX container-registry.oracle.com
[oracle@oel75 ~]$ docker login -u monowar.mukul@gmail.com -p XXXX container-registry.oracle.com
For this article, tree structure of the docker file before building image was as below —
I download and staged Oracle database software as below path, no need to unzipped —
[root@opsdev 19.3.0]#
cd /u01/app/odbdocker/docker-images-master/OracleDatabase/SingleInstance/dockerfiles/19.3.0
[root@opsdev 19.3.0]# cp /media/sf_software/Software/LINUX.X64_193000_db_home.zip .
cd /u01/app/odbdocker/docker-images-master/OracleDatabase/SingleInstance/dockerfiles/19.3.0
[root@opsdev 19.3.0]# cp /media/sf_software/Software/LINUX.X64_193000_db_home.zip .
[root@opsdev dockerfiles]# ./buildDockerImage.sh -v 19.3.0 -e
dockercontainer.sh
for d in `docker ps | awk ‘{print $1}’ | tail -n +2`; do
d_name=`docker inspect -f {{.Name}} $d`
echo “=========================================================”
echo “$d_name ($d) container size:”
# sudo du -d 2 -h /var/lib/docker/devicemapper | grep `docker inspect -f “{{.Id}}” $d`
echo “$d_name ($d) volumes:”
for mount in `docker inspect -f “{{range .Mounts}} {{.Source}}:{{.Destination}}
{{end}}” $d`; do
size=`echo $mount | cut -d’:’ -f1 | sudo xargs du -d 0 -h`
mnt=`echo $mount | cut -d’:’ -f2`
echo “$size mounted on $mnt”
#echo “=========================================================”
#echo “$d_name ($d) container OS statistics:”
#docker stats $(docker ps — format={{.Names}}) — no-stream
done
doneecho “=========================================================”
echo “$d_name ($d) container OS statistics:”
docker stats $(docker ps — format={{.Names}}) — no-stream
Comments