Creating an Oracle Database Docker image

Gerald Venzl
Oracle Developers
Published in
16 min readAug 21, 2017

Oracle has released Docker build files for the Oracle Database on Github. With those build files one can go ahead and build his or her own Docker image for the Oracle Database. If you don’t know what Docker is you should go and check it out. It’s a cool technology based on the Linux containers technology that allows you to containerize your application, whatever that application may be. Naturally, it didn’t take long for people to start looking at containerizing databases as well which makes a lot of sense, especially for, but not only, development and test environments. Here is a detailed blog post on how to containerize your Oracle Database by using those build files that Oracle has provided.

What you need

Environment

My environment is as follows:

  • Oracle Linux 7.3 (4.1.12–94.3.8.el7uek.x86_64)
  • Docker 17.03.1-ce (docker-engine.x86_64 17.03.1.ce-3.0.1.el7)
  • Oracle Database 12.2.0.1 Enterprise Edition

Docker setup

The first thing, if not already done so, is to setup Docker on the environment. Luckily this is fairly straight forward. Docker is shipped as an addon with Oracle Linux 7 UEK4. As I’m running on such environment all I have to do is to is to enable the addons yum repository and install the docker-engine package. Note, this is done as the root Linux user:

Enable OL7 addons repo

[root@localhost ~]# yum-config-manager enable *addons*
Loaded plugins: langpacks
================================================================== repo: ol7_addons ==================================================================
[ol7_addons]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7Server
baseurl = http://public-yum.oracle.com/repo/OracleLinux/OL7/addons/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7Server/ol7_addons
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = True
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7Server/ol7_addons/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7Server/ol7_addons/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
hdrdir = /var/cache/yum/x86_64/7Server/ol7_addons/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Oracle Linux 7Server Add ons (x86_64)
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7Server/ol7_addons
pkgdir = /var/cache/yum/x86_64/7Server/ol7_addons/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = ol7_addons/x86_64
ui_repoid_vars = releasever,
basearch
username =

Install docker-engine

[root@localhost ~]# yum install docker-engine
Loaded plugins: langpacks, ulninfo
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:17.03.1.ce-3.0.1.el7 will be installed
--> Processing Dependency: docker-engine-selinux >= 17.03.1.ce-3.0.1.el7 for package: docker-engine-17.03.1.ce-3.0.1.el7.x86_64
--> Running transaction check
---> Package selinux-policy-targeted.noarch 0:3.13.1-102.0.3.el7_3.16 will be updated
---> Package selinux-policy-targeted.noarch 0:3.13.1-166.0.2.el7 will be an update
--> Processing Dependency: selinux-policy = 3.13.1-166.0.2.el7 for package: selinux-policy-targeted-3.13.1-166.0.2.el7.noarch
--> Running transaction check
---> Package selinux-policy.noarch 0:3.13.1-102.0.3.el7_3.16 will be updated
---> Package selinux-policy.noarch 0:3.13.1-166.0.2.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Installing:
docker-engine x86_64 17.03.1.ce-3.0.1.el7 ol7_addons 19 M
Updating:
selinux-policy-targeted noarch 3.13.1-166.0.2.el7 ol7_latest 6.5 M
Updating for dependencies:
selinux-policy noarch 3.13.1-166.0.2.el7 ol7_latest 435 k

Transaction Summary
======================================================================================================================================================
Install 1 Package
Upgrade 1 Package (+1 Dependent package)

Total download size: 26 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for ol7_latest
(1/3): selinux-policy-3.13.1-166.0.2.el7.noarch.rpm | 435 kB 00:00:00
(2/3): selinux-policy-targeted-3.13.1-166.0.2.el7.noarch.rpm | 6.5 MB 00:00:01
(3/3): docker-engine-17.03.1.ce-3.0.1.el7.x86_64.rpm | 19 MB 00:00:04
------------------------------------------------------------------------------------------------------------------------------------------------------
Total 6.2 MB/s | 26 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : selinux-policy-3.13.1-166.0.2.el7.noarch 1/5
Updating : selinux-policy-targeted-3.13.1-166.0.2.el7.noarch 2/5
Installing : docker-engine-17.03.1.ce-3.0.1.el7.x86_64 3/5
Cleanup : selinux-policy-targeted-3.13.1-102.0.3.el7_3.16.noarch 4/5
Cleanup : selinux-policy-3.13.1-102.0.3.el7_3.16.noarch 5/5
Verifying : selinux-policy-targeted-3.13.1-166.0.2.el7.noarch 1/5
Verifying : selinux-policy-3.13.1-166.0.2.el7.noarch 2/5
Verifying : docker-engine-17.03.1.ce-3.0.1.el7.x86_64 3/5
Verifying : selinux-policy-targeted-3.13.1-102.0.3.el7_3.16.noarch 4/5
Verifying : selinux-policy-3.13.1-102.0.3.el7_3.16.noarch 5/5

Installed:
docker-engine.x86_64 0:17.03.1.ce-3.0.1.el7

Updated:
selinux-policy-targeted.noarch 0:3.13.1-166.0.2.el7

Dependency Updated:
selinux-policy.noarch 0:3.13.1-166.0.2.el7

Complete!

And that’s it! Docker is now installed on the machine. Before I proceed with building an image I first have to configure my environment appropriately.

Enable non-root user

The first thing I want to do is to enable a non-root user to communicate with the Docker engine. Enabling a non-root user is fairly straight forward as well. When Docker was installed a new Unix group docker was created along with it. If you want to allow a user to communicate with the Docker daemon directly, hence avoiding to run as the root user, all you have to do is to add that user to the docker group. In my case I want to add the oracle user to that group:

[root@localhost ~]# id oracle
uid=1000(oracle) gid=1001(oracle) groups=1001(oracle),1000(dba)
[root@localhost ~]# usermod -a -G docker oracle
[root@localhost ~]# id oracle
uid=1000(oracle) gid=1001(oracle) groups=1001(oracle),1000(dba),981(docker)

Increase base image size

Before I go ahead and run the image build I want to double check one important parameter: The default base image size for the Docker container. In the past Docker came with a maximum container size of 10 GB by default. While this is more than enough for running some applications inside Docker containers this needed to be increased for Oracle Database. The Oracle Database 12.2.0.1 image requires about 13GB of space for the image build.

Recently the default size has been increased to 25GB which will be more than enough for the Oracle Database image. The setting can be found and double checked in /etc/sysconfig/docker-storage as the storage-opt dm.basesize parameter:

[root@localhost ~]# cat /etc/sysconfig/docker-storage
# This file may be automatically generated by an installation program.

# By default, Docker uses a loopback-mounted sparse file in
# /var/lib/docker. The loopback makes it slower, and there are some
# restrictive defaults, such as 100GB max storage.

# If your installation did not set a custom storage for Docker, you
# may do it below.

# Example: Use a custom pair of raw logical volumes (one for metadata,
# one for data).
# DOCKER_STORAGE_OPTIONS = --storage-opt dm.metadatadev=/dev/mylogvol/my-docker-metadata --storage-opt dm.datadev=/dev/mylogvol/my-docker-data
DOCKER_STORAGE_OPTIONS= --storage-driver devicemapper --storage-opt dm.basesize=25G

Start and enable the Docker service

The final step is to start the docker service and configure it to start at boot time. This is done via the systemctl command:

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl status docker
● 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 Sun 2017-08-20 14:18:16 EDT; 5s ago
Docs: https://docs.docker.com
Main PID: 19203 (dockerd)
Memory: 12.8M
CGroup: /system.slice/docker.service
├─19203 /usr/bin/dockerd --selinux-enabled --storage-driver devicemapper --storage-opt dm.basesize=25G
└─19207 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state...

As a last step you can verify the setup and the base image size (check for Base Device Size:) via docker info:

[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: devicemapper
Pool Name: docker-249:0-202132724-pool
Pool Blocksize: 65.54 kB
Base Device Size: 26.84 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 14.42 MB
Data Space Total: 107.4 GB
Data Space Available: 47.98 GB
Metadata Space Used: 581.6 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.135-RHEL7 (2016-11-16)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
seccomp
Profile: default
selinux
Kernel Version: 4.1.12-94.3.8.el7uek.x86_64
Operating System: Oracle Linux Server 7.3
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 7.795 GiB
Name: localhost.localdomain
ID: D7CR:3DGV:QUGO:X7EB:AVX3:DWWW:RJIA:QVVT:I2YR:KJXV:ALR4:WLBV
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

That concludes the installation of Docker itself.

Building the Oracle Database Docker image

Now that Docker is up and running I can start building the image. First I need to get the Docker build files and the Oracle install binaries, both are easy to obtain as shown below. Note that I use the oracle Linux user for all the following steps, which I have enabled previously to communicate with the Docker daemon:

Obtaining the required files

Github build files

First I have to download the Docker build files. There are various ways to do this. I can for example clone the Git repository directly. But for simplicity and for the people who aren’t familiar with git I will just use the download option on Github itself. If you go to the main repository URL https://github.com/oracle/docker-images/ you will see a green button saying “Clone or download” and by clicking on it you will have the option “Download ZIP“. Alternatively you can also just download the repository directly via the static URL: https://github.com/oracle/docker-images/archive/master.zip

[oracle@localhost ~]$ wget https://github.com/oracle/docker-images/archive/master.zip
--2017-08-20 14:31:32-- https://github.com/oracle/docker-images/archive/master.zip
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/oracle/docker-images/zip/master [following]
--2017-08-20 14:31:33-- https://codeload.github.com/oracle/docker-images/zip/master
Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘master.zip’

[ ] 4,411,616 3.37MB/s in 1.2s

2017-08-20 14:31:34 (3.37 MB/s) - ‘master.zip’ saved [4411616]

[oracle@localhost ~]$ unzip master.zip
Archive: master.zip
21041a743e4b0a910b0e51e17793bb7b0b18efef
creating: docker-images-master/
extracting: docker-images-master/.gitattributes
inflating: docker-images-master/.gitignore
inflating: docker-images-master/.gitmodules
inflating: docker-images-master/CODEOWNERS
inflating: docker-images-master/CONTRIBUTING.md
...
...
...
creating: docker-images-master/OracleDatabase/
extracting: docker-images-master/OracleDatabase/.gitignore
inflating: docker-images-master/OracleDatabase/COPYRIGHT
inflating: docker-images-master/OracleDatabase/LICENSE
inflating: docker-images-master/OracleDatabase/README.md
creating: docker-images-master/OracleDatabase/dockerfiles/
...
...
...
inflating: docker-images-master/README.md
[oracle@localhost ~]$

Oracle installation binaries

For the Oracle binaries just download them from where you usually would download them. Oracle Technology Network is probably the place that most people go to. Once you have downloaded them you can proceed with building the image:

[oracle@localhost ~]$ ls -al *database*zip
-rw-r--r--. 1 oracle oracle 1354301440 Aug 20 14:40 linuxx64_12201_database.zip

Building the image

Now that I have all the files it’s time to build the Docker image. You will find a separate README.md in the docker-images-master/OracleDatabase directory which explains the build process in more details. Make sure that you always read that file as it will always reflect the latest changes in the build files! You will also find a buildDockerImage.sh shell script in the docker-images-master/OracleDatabase/dockerfiles directory that does the legwork of the build for you. For the build it is essential that I copy the install files into the correct version directory. As I’m going to create an Oracle Database 12.2.0.1 image I need to copy the install zip file into docker-images-master/OracleDatabase/dockerfiles/12.2.0.1:

[oracle@localhost ~]$ cd docker-images-master/OracleDatabase/dockerfiles/12.2.0.1/
[oracle@localhost 12.2.0.1]$ cp ~/linuxx64_12201_database.zip .
[oracle@localhost 12.2.0.1]$ ls -al
total 3372832
drwxrwxr-x. 2 oracle oracle 4096 Aug 20 14:44 .
drwxrwxr-x. 5 oracle oracle 77 Aug 19 00:35 ..
-rwxr-xr-x. 1 oracle oracle 1259 Aug 19 00:35 checkDBStatus.sh
-rwxr-xr-x. 1 oracle oracle 909 Aug 19 00:35 checkSpace.sh
-rw-rw-r--. 1 oracle oracle 62 Aug 19 00:35 Checksum.ee
-rw-rw-r--. 1 oracle oracle 62 Aug 19 00:35 Checksum.se2
-rwxr-xr-x. 1 oracle oracle 2964 Aug 19 00:35 createDB.sh
-rw-rw-r--. 1 oracle oracle 9203 Aug 19 00:35 dbca.rsp.tmpl
-rw-rw-r--. 1 oracle oracle 6878 Aug 19 00:35 db_inst.rsp
-rw-rw-r--. 1 oracle oracle 2550 Aug 19 00:35 Dockerfile.ee
-rw-rw-r--. 1 oracle oracle 2552 Aug 19 00:35 Dockerfile.se2
-rwxr-xr-x. 1 oracle oracle 2261 Aug 19 00:35 installDBBinaries.sh
-rw-r--r--. 1 oracle oracle 3453696911 Aug 20 14:45 linuxx64_12201_database.zip
-rwxr-xr-x. 1 oracle oracle 6151 Aug 19 00:35 runOracle.sh
-rwxr-xr-x. 1 oracle oracle 1026 Aug 19 00:35 runUserScripts.sh
-rwxr-xr-x. 1 oracle oracle 769 Aug 19 00:35 setPassword.sh
-rwxr-xr-x. 1 oracle oracle 879 Aug 19 00:35 setupLinuxEnv.sh
-rwxr-xr-x. 1 oracle oracle 689 Aug 19 00:35 startDB.sh
[oracle@localhost 12.2.0.1]$

Now that the zip file is in place I am ready to invoke the buildDockerImage.sh shell script in the dockerfiles folder. The script takes a couple of parameters, -v for the version and -e for telling it that I want Enterprise Edition. Note: The build of the image will pull the Oracle Linux slim base image and execute a yum install as well as a yum upgrade inside the container. For it to success to have to have internet connectivity:

[oracle@localhost 12.2.0.1]$ cd ..
[oracle@localhost dockerfiles]$ ./buildDockerImage.sh -v 12.2.0.1 -e
Checking if required packages are present and valid...
linuxx64_12201_database.zip: OK
==========================
DOCKER info:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: devicemapper
Pool Name: docker-249:0-202132724-pool
Pool Blocksize: 65.54 kB
Base Device Size: 26.84 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 14.42 MB
Data Space Total: 107.4 GB
Data Space Available: 47.98 GB
Metadata Space Used: 581.6 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.135-RHEL7 (2016-11-16)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
seccomp
Profile: default
selinux
Kernel Version: 4.1.12-94.3.8.el7uek.x86_64
Operating System: Oracle Linux Server 7.3
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 7.795 GiB
Name: localhost.localdomain
ID: D7CR:3DGV:QUGO:X7EB:AVX3:DWWW:RJIA:QVVT:I2YR:KJXV:ALR4:WLBV
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
==========================
Building image 'oracle/database:12.2.0.1-ee' ...
Sending build context to Docker daemon 3.454 GB
Step 1/16 : FROM oraclelinux:7-slim
7-slim: Pulling from library/oraclelinux
3152c71f8d80: Pull complete
Digest: sha256:e464042b724d41350fb3ac2c2f84bd9d28d98302c9ebe66048a5367682e5fad2
Status: Downloaded newer image for oraclelinux:7-slim
---> c0feb50f7527
Step 2/16 : MAINTAINER Gerald Venzl
---> Running in e442cae35367
---> 08f875cea39d
...
...
...

Step 15/16 : EXPOSE 1521 5500
---> Running in 4476c1c236e1
---> d01d39e39920
Removing intermediate container 4476c1c236e1
Step 16/16 : CMD exec $ORACLE_BASE/$RUN_FILE
---> Running in 8757674cc3d5
---> 98129834d5ad
Removing intermediate container 8757674cc3d5
Successfully built 98129834d5ad

Oracle Database Docker Image for 'ee' version 12.2.0.1 is ready to be extended:

--> oracle/database:12.2.0.1-ee

Build completed in 802 seconds.

Starting and connecting to the Oracle Database inside a Docker container

Once the build was successful I can now start and run the Oracle Database inside a Docker container. All I have to do is to issue the docker run command and pass in the appropriate parameters. One important parameter is the -p for the mapping of ports inside the container to the outside world. This is required so that I can also connect to the database from outside the Docker container. Another important parameter is the -v parameter which allows me to keep the data files of the database in a location outside the Docker container. This is important as it will allow me to preserve my data even when the container is thrown away. You should always use the -v parameter or create a named Docker volume! The last useful parameter that I’m going to use is the --name parameter which specifies the name of the Docker container itself. If omitted a random name will be generated. However, passing on a name will allow me to refer to the container via that name later on:

[oracle@localhost dockerfiles]$ cd ~
[oracle@localhost ~]$ mkdir oradata
[oracle@localhost ~]$ chmod a+w oradata
[oracle@localhost ~]$ docker run --name oracle-ee -p 1521:1521 -v /home/oracle/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: 3y4RL1K7org=1

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-AUG-2017 19:07:55

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

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

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/e3d1a2314421/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 12.2.0.1.0 - Production
Start Date 20-AUG-2017 19:07:56
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/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/e3d1a2314421/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
[WARNING] [DBT-10102] The listener configuration is not selected for the database. EM DB Express URL will not be accessible.
CAUSE: The database should be registered with a listener in order to access the EM DB Express URL.
ACTION: Select a listener to be registered or created with the database.
Copying database files
1% complete
13% complete
25% complete
Creating and starting Oracle instance
26% complete
30% complete
31% complete
35% complete
38% complete
39% complete
41% complete
Completing Database Creation
42% complete
43% complete
44% complete
46% complete
47% complete
50% complete
Creating Pluggable Databases
55% complete
75% complete
Executing Post Configuration Actions
100% complete
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.

SQL*Plus: Release 12.2.0.1.0 Production on Sun Aug 20 19:16:01 2017

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

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>
System altered.

SQL>
Pluggable database altered.

SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
Completed: alter pluggable database ORCLPDB1 open
2017-08-20T19:16:01.025829+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
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"
2017-08-20T19:16:01.889003+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

On the very first startup of the container a new database is being created. Subsequent startups of the same container or newly created containers pointing to the same volume will just start up the database again. Once the database is created and or started the container will run a tail -f on the Oracle Database alert.log file. This is done for convenience so that issuing a docker logs command will actually print the logs of the database running inside that container. Once the database is created or started up you will see the line DATABASE IS READY TO USE! in the output. After that you can connect to the database.

Resetting the database admin accounts passwords

The startup script also generated a password for the database admin accounts. You can find the password next to the line ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: in the output. You can either use that password going forward or you can reset it to a password of your choice. The container provides a script called setPassword.sh for resetting the password. In a new shell just execute following command against the running container:

[oracle@localhost ~]$ docker exec oracle-ee ./setPassword.sh LetsDocker
The Oracle base remains unchanged with value /opt/oracle

SQL*Plus: Release 12.2.0.1.0 Production on Sun Aug 20 19:17:08 2017

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

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>
User altered.

SQL>
User altered.

SQL>
Session altered.

SQL>
User altered.

SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Connecting to the Oracle Database

Now that the container is running and the port 1521 mapped to the outside world I can connect to the database inside the container:

[oracle@localhost ~]$ sql system/LetsDocker@//localhost:1521/ORCLPDB1

SQLcl: Release 4.2.0 Production on Sun Aug 20 19:56:43 2017

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

Last Successful login time: Sun Aug 20 2017 12:21:42 -07:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> grant connect, resource to gvenzl identified by supersecretpwd;

Grant succeeded.

SQL> conn gvenzl/supersecretpwd@//localhost:1521/ORCLPDB1
Connected.
SQL>

Stopping the Oracle Database Docker container

If you wish to stop the Docker container you can just do so via the docker stop command. All you will have to do is to issue the command and pass on the container name or id. This will trigger the container to issue a shutdown immediate for the database inside the container. By default Docker will only allow 10 seconds for the container to shutdown before killing it. For applications that may be fine but for persistent containers such as the Oracle Database container you may want to give the container a bit more time to shutdown the database appropriately. You can do that via the -t option that allows you to pass on a new timeout in seconds for the container to shutdown successfully. I will give the database 30 seconds to shutdown but it’s important to point out that it doesn’t really matter how long you give the container to shutdown. Once the database is shutdown the container will exit normal. It will not wait all the seconds that you have specified until returning control. So even if you give it 10 minutes (600 seconds) it will still return as soon as the database is shutdown. Just keep that in mind when specifying a timeout for busy database containers:

[oracle@localhost ~]$ docker stop -t 30 oracle-ee
oracle-ee

Restarting the Oracle Database Docker container

A stopped container can always be restarted via the docker start command:

[oracle@localhost ~]$ docker start oracle-ee
oracle-ee

The docker start command will put the container into background and return control immediately. You can check the status of the container via the docker logs command which should print the same DATABASE IS READY TO USE! line. You will also see that this time the database was just restarted rather than created. Note, a docker logs -f will follow the log output, i.e. keep on printing new lines:

[oracle@localhost ~]$ docker logs oracle-ee
...
...
...
SQL*Plus: Release 12.2.0.1.0 Production on Sun Aug 20 19:30:31 2017

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

Connected to an idle instance.

SQL> ORACLE instance started.

Total System Global Area 1610612736 bytes
Fixed Size 8793304 bytes
Variable Size 520094504 bytes
Database Buffers 1073741824 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
ORCLPDB1(3):Undo initialization finished serial:0 start:6800170 end:6800239 diff:69 ms (0.1 seconds)
ORCLPDB1(3):Database Characterset for ORCLPDB1 is AL32UTF8
ORCLPDB1(3):Opatch validation is skipped for PDB ORCLPDB1 (con_id=0)
ORCLPDB1(3):Opening pdb with no Resource Manager plan active
2017-08-20T19:30:43.703897+00:00
Pluggable database ORCLPDB1 opened read write

Now that the database is up and running again I can connect once more to the database inside:

[oracle@localhost ~]$ sql gvenzl/supersecretpwd@//localhost:1521/ORCLPDB1

SQLcl: Release 4.2.0 Production on Sun Aug 20 20:10:28 2017

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

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select sysdate from dual;

SYSDATE
---------
20-AUG-17

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Summary

This concludes how to containerize the Oracle Database using Docker. Note that Oracle has also provided build files for other Oracle Database versions and editions. The steps described above are largely the same but you should always refer to the README.md that comes with the build files. In there you will also find more options for how to run your Oracle Database containers.

Github repository: https://github.com/oracle/docker-images/tree/master/OracleDatabase

Originally published at geraldonit.com on August 21, 2017.

--

--

Gerald Venzl
Oracle Developers

Developer, Oracle expert, performance enthusiast and genuine technology geek.