Creating an Oracle Database Docker image

Gerald Venzl
Oracle Developers
Published in
16 min readNov 13, 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 = Truebandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/7Serverbaseurl = http://public-yum.oracle.com/repo/OracleLinux/OL7/addons/x86_64/cache = 0cachedir = /var/cache/yum/x86_64/7Server/ol7_addonscheck_config_file_age = Truecompare_providers_priority = 80cost = 1000deltarpm_metadata_percentage = 100deltarpm_percentage =enabled = Trueenablegroups = Trueexclude =failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/7Server/ol7_addons/gpgcadirgpgcakey =gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/7Server/ol7_addons/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oraclehdrdir = /var/cache/yum/x86_64/7Server/ol7_addons/headershttp_caching = allincludepkgs =ip_resolve =keepalive = Truekeepcache = Falsemddownloadpolicy = sqlitemdpolicy = group:smallmediaid =metadata_expire = 21600metadata_expire_filter = read-only:presentmetalink =minrate = 0mirrorlist =mirrorlist_expire = 86400name = Oracle Linux 7Server Add ons (x86_64)old_base_cache_dir =password =persistdir = /var/lib/yum/repos/x86_64/7Server/ol7_addonspkgdir = /var/cache/yum/x86_64/7Server/ol7_addons/packagesproxy = Falseproxy_dict =proxy_password =proxy_username =repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert =sslclientcert =sslclientkey =sslverify = Truethrottle = 0timeout = 30.0ui_id = ol7_addons/x86_64ui_repoid_vars = releasever,basearchusername =

Install docker-engine

[root@localhost ~]# yum install docker-engineLoaded plugins: langpacks, ulninfoResolving 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 ResolutionDependencies Resolved======================================================================================================================================================Package Arch Version Repository Size======================================================================================================================================================Installing:docker-engine x86_64 17.03.1.ce-3.0.1.el7 ol7_addons 19 MUpdating:selinux-policy-targeted noarch 3.13.1-166.0.2.el7 ol7_latest 6.5 MUpdating for dependencies:selinux-policy noarch 3.13.1-166.0.2.el7 ol7_latest 435 kTransaction Summary======================================================================================================================================================Install 1 PackageUpgrade 1 Package (+1 Dependent package)Total download size: 26 MIs this ok [y/d/N]: yDownloading 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:04Running transaction checkRunning transaction testTransaction test succeededRunning transactionUpdating : selinux-policy-3.13.1-166.0.2.el7.noarch 1/5Updating : selinux-policy-targeted-3.13.1-166.0.2.el7.noarch 2/5Installing : docker-engine-17.03.1.ce-3.0.1.el7.x86_64 3/5Cleanup : selinux-policy-targeted-3.13.1-102.0.3.el7_3.16.noarch 4/5Cleanup : selinux-policy-3.13.1-102.0.3.el7_3.16.noarch 5/5Verifying : selinux-policy-targeted-3.13.1-166.0.2.el7.noarch 1/5Verifying : selinux-policy-3.13.1-166.0.2.el7.noarch 2/5Verifying : docker-engine-17.03.1.ce-3.0.1.el7.x86_64 3/5Verifying : selinux-policy-targeted-3.13.1-102.0.3.el7_3.16.noarch 4/5Verifying : selinux-policy-3.13.1-102.0.3.el7_3.16.noarch 5/5Installed:docker-engine.x86_64 0:17.03.1.ce-3.0.1.el7Updated:selinux-policy-targeted.noarch 0:3.13.1-166.0.2.el7Dependency Updated:selinux-policy.noarch 0:3.13.1-166.0.2.el7Complete!

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 oracleuid=1000(oracle) gid=1001(oracle) groups=1001(oracle),1000(dba)[root@localhost ~]# usermod -a -G docker oracle[root@localhost ~]# id oracleuid=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-dataDOCKER_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 dockerCreated 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 EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)Drop-In: /etc/systemd/system/docker.service.d└─docker-sysconfig.confActive: active (running) since Sun 2017-08-20 14:18:16 EDT; 5s agoDocs: https://docs.docker.comMain PID: 19203 (dockerd)Memory: 12.8MCGroup: /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 infoContainers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 17.03.1-ceStorage Driver: devicemapperPool Name: docker-249:0-202132724-poolPool Blocksize: 65.54 kBBase Device Size: 26.84 GBBacking Filesystem: xfsData file: /dev/loop0Metadata file: /dev/loop1Data Space Used: 14.42 MBData Space Total: 107.4 GBData Space Available: 47.98 GBMetadata Space Used: 581.6 kBMetadata Space Total: 2.147 GBMetadata Space Available: 2.147 GBThin Pool Minimum Free Space: 10.74 GBUdev Sync Supported: trueDeferred Removal Enabled: falseDeferred Deletion Enabled: falseDeferred Deleted Device Count: 0Data loop file: /var/lib/docker/devicemapper/devicemapper/dataWARNING: 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/metadataLibrary Version: 1.02.135-RHEL7 (2016-11-16)Logging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host macvlan null overlaySwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 4ab9917febca54791c5f071a9d1f404867857fccrunc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfeinit version: 949e6faSecurity Options:seccompProfile: defaultselinuxKernel Version: 4.1.12-94.3.8.el7uek.x86_64Operating System: Oracle Linux Server 7.3OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 7.795 GiBName: localhost.localdomainID: D7CR:3DGV:QUGO:X7EB:AVX3:DWWW:RJIA:QVVT:I2YR:KJXV:ALR4:WLBVDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Experimental: falseInsecure Registries:127.0.0.0/8Live 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.zipResolving github.com (github.com)... 192.30.255.113, 192.30.255.112Connecting to github.com (github.com)|192.30.255.113|:443... connected.HTTP request sent, awaiting response... 302 FoundLocation: https://codeload.github.com/oracle/docker-images/zip/master [following]--2017-08-20 14:31:33-- https://codeload.github.com/oracle/docker-images/zip/masterResolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.HTTP request sent, awaiting response... 200 OKLength: unspecified [application/zip]Saving to: ‘master.zip’[ ] 4,411,616 3.37MB/s in 1.2s2017-08-20 14:31:34 (3.37 MB/s) - ‘master.zip’ saved [4411616][oracle@localhost ~]$ unzip master.zipArchive: master.zip21041a743e4b0a910b0e51e17793bb7b0b18efefcreating: docker-images-master/extracting: docker-images-master/.gitattributesinflating: docker-images-master/.gitignoreinflating: docker-images-master/.gitmodulesinflating: docker-images-master/CODEOWNERSinflating: docker-images-master/CONTRIBUTING.md.........creating: docker-images-master/OracleDatabase/extracting: docker-images-master/OracleDatabase/.gitignoreinflating: docker-images-master/OracleDatabase/COPYRIGHTinflating: docker-images-master/OracleDatabase/LICENSEinflating: docker-images-master/OracleDatabase/README.mdcreating: 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/SingleInstancedirectory 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/SingleInstance/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/SingleInstance/dockerfiles/12.2.0.1:

[oracle@localhost ~]$ cd docker-images-master/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1/[oracle@localhost 12.2.0.1]$ cp ~/linuxx64_12201_database.zip .[oracle@localhost 12.2.0.1]$ ls -altotal 3372832drwxrwxr-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 -eChecking if required packages are present and valid...linuxx64_12201_database.zip: OK==========================DOCKER info:Containers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 17.03.1-ceStorage Driver: devicemapperPool Name: docker-249:0-202132724-poolPool Blocksize: 65.54 kBBase Device Size: 26.84 GBBacking Filesystem: xfsData file: /dev/loop0Metadata file: /dev/loop1Data Space Used: 14.42 MBData Space Total: 107.4 GBData Space Available: 47.98 GBMetadata Space Used: 581.6 kBMetadata Space Total: 2.147 GBMetadata Space Available: 2.147 GBThin Pool Minimum Free Space: 10.74 GBUdev Sync Supported: trueDeferred Removal Enabled: falseDeferred Deletion Enabled: falseDeferred Deleted Device Count: 0Data loop file: /var/lib/docker/devicemapper/devicemapper/dataWARNING: 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/metadataLibrary Version: 1.02.135-RHEL7 (2016-11-16)Logging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host macvlan null overlaySwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 4ab9917febca54791c5f071a9d1f404867857fccrunc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfeinit version: 949e6faSecurity Options:seccompProfile: defaultselinuxKernel Version: 4.1.12-94.3.8.el7uek.x86_64Operating System: Oracle Linux Server 7.3OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 7.795 GiBName: localhost.localdomainID: D7CR:3DGV:QUGO:X7EB:AVX3:DWWW:RJIA:QVVT:I2YR:KJXV:ALR4:WLBVDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false==========================Building image 'oracle/database:12.2.0.1-ee' ...Sending build context to Docker daemon 3.454 GBStep 1/16 : FROM oraclelinux:7-slim7-slim: Pulling from library/oraclelinux3152c71f8d80: Pull completeDigest: sha256:e464042b724d41350fb3ac2c2f84bd9d28d98302c9ebe66048a5367682e5fad2Status: Downloaded newer image for oraclelinux:7-slim---> c0feb50f7527Step 2/16 : MAINTAINER Gerald Venzl---> Running in e442cae35367---> 08f875cea39d.........Step 15/16 : EXPOSE 1521 5500---> Running in 4476c1c236e1---> d01d39e39920Removing intermediate container 4476c1c236e1Step 16/16 : CMD exec $ORACLE_BASE/$RUN_FILE---> Running in 8757674cc3d5---> 98129834d5adRemoving intermediate container 8757674cc3d5Successfully built 98129834d5adOracle Database Docker Image for 'ee' version 12.2.0.1 is ready to be extended:--> oracle/database:12.2.0.1-eeBuild 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-eeORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: 3y4RL1K7org=1LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 20-AUG-2017 19:07:55Copyright (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 - ProductionSystem parameter file is /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.oraLog messages written to /opt/oracle/diag/tnslsnr/e3d1a2314421/listener/alert/log.xmlListening 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 LISTENERVersion TNSLSNR for Linux: Version 12.2.0.1.0 - ProductionStart Date 20-AUG-2017 19:07:56Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.oraListener Log File /opt/oracle/diag/tnslsnr/e3d1a2314421/listener/alert/log.xmlListening Endpoints Summary...(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))The listener supports no servicesThe 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 files1% complete13% complete25% completeCreating and starting Oracle instance26% complete30% complete31% complete35% complete38% complete39% complete41% completeCompleting Database Creation42% complete43% complete44% complete46% complete47% complete50% completeCreating Pluggable Databases55% complete75% completeExecuting Post Configuration Actions100% completeLook 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 2017Copyright (c) 1982, 2016, Oracle. All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit ProductionSQL>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 open2017-08-20T19:16:01.025829+00:00ORCLPDB1(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 AUTOORCLPDB1(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 AUTOORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"2017-08-20T19:16:01.889003+00:00ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATECompleted: 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 LetsDockerThe Oracle base remains unchanged with value /opt/oracleSQL*Plus: Release 12.2.0.1.0 Production on Sun Aug 20 19:17:08 2017Copyright (c) 1982, 2016, Oracle. All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit ProductionSQL>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/ORCLPDB1SQLcl: Release 4.2.0 Production on Sun Aug 20 19:56:43 2017Copyright (c) 1982, 2017, Oracle. All rights reserved.Last Successful login time: Sun Aug 20 2017 12:21:42 -07:00Connected to:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit ProductionSQL> grant connect, resource to gvenzl identified by supersecretpwd;Grant succeeded.SQL> conn gvenzl/supersecretpwd@//localhost:1521/ORCLPDB1Connected.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-eeoracle-ee

Restarting the Oracle Database Docker container

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

[oracle@localhost ~]$ docker start oracle-eeoracle-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 2017Copyright (c) 1982, 2016, Oracle.  All rights reserved.Connected to an idle instance.SQL> ORACLE instance started.Total System Global Area 1610612736 bytesFixed Size          8793304 bytesVariable Size         520094504 bytesDatabase Buffers     1073741824 bytesRedo Buffers            7983104 bytesDatabase 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 AL32UTF8ORCLPDB1(3):Opatch validation is skipped for PDB ORCLPDB1 (con_id=0)ORCLPDB1(3):Opening pdb with no Resource Manager plan active2017-08-20T19:30:43.703897+00:00Pluggable 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/ORCLPDB1SQLcl: Release 4.2.0 Production on Sun Aug 20 20:10:28 2017Copyright (c) 1982, 2017, Oracle. All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit ProductionSQL> select sysdate from dual;SYSDATE---------20-AUG-17SQL> exitDisconnected 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

Original article: https://geraldonit.com/2017/08/21/creating-an-oracle-database-docker-image/

--

--

Gerald Venzl
Oracle Developers

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