Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Build Oracle Database Docker Image


This Gist describes the steps to build an Oracle Database Docker Image. It also demonstrates using a custom script to convert the created database to use Extended Data Types (32K VARCHAR2).

Download Database Binaries from Oracle Technology Network

Download the linux x86-64 ZIP archive from here.

Check out the Oracle Docker Images from Github

There's a few ways to do this using an SVN or GIT client, but I just go to the project's home page, and click the button on the right hand side labeled 'Clone or Download' and then click 'Download Zip'.

Next unzip this archive of the project that you just downloaded, for example:

cd ~/work/docker
unzip ~/Downloads/

Move the Database Binaries to the correct location

To build the Docker image, you'll use a script named, for this script to work the Oracle Database binaries need to be placed in the correct location, for example:

cd ~/work/docker/docker-images-master/OracleDatabase/
mv ~/Downloads/ ./

This places the ZIP archive containing the Oracle Database binaries in the expected sub-folder

Configure the Proxy if necessary

If you're behind a proxy, you'll need to ensure the http_proxy and https_proxy environment variables are set, so the proxy configuration can be propagated to the created Docker Container. If this is not done correctly then yum will not be able to reach any repositories.

For example:

export http_proxy=
export https_proxy=

Build the Docker Image

To build the Docker image use the script, it's usage is described in the README. First let's ensure the script is executable:

cd ~/work/docker/docker-images-master/OracleDatabase/
chmod +x ./

Next invoke the script to build the image, to build a enterprise edition image:

cd ~/work/docker/docker-images-master/OracleDatabase/
./ -v -e

Go get a coffee, this step takes a while, for me it took about 16 minutes.

Run the Docker Image

When it comes to running the Docker Image, you have several choices to make, read the docs for more detail on this. I'm only going to change a few things:

  • set the name of the PDB created to ORCL
  • Store the database data on the host machine, this enables me to blow away the docker container at any time and re-create it without losing any data. In effect I'm separating the database 'engine' (the docker container) from the database storage (the volume on the host where the database storage is persisted).
  • Configure the Database to use Extended Data Types (increase max VARCHAR2 to 32767 bytes).

Prepare the storage volume

I created a folder within my home folder:

cd ~/work/docker
mkdir oradata

Note the documentation states this folder must be owned by an operating system user named oracle. On my Mac OS host, I found I didn't need to create an oracle user or give it ownership of this folder.

Extended Data Types

In 12.1 and later VARCHAR2 fields can be configured to hold up to 32K bytes. However this feature is off by default, so we need to do some scripting to reconfigure the database to use extended data types. We want these scripts to run after the database is first setup, so we'll mount a volume as part of the docker run command which will cause those scripts to be executed.

The script needed is attached to this gist, so first ensure you have downloaded this script into a folder. The easiest way to do this is to click the 'Download ZIP' button at the top right of this page and then unzip the downloaded archive into a folder, for example:

cd ~/work/docker
mkdir db_setup_scripts
cd db_setup_scripts
unzip -j ~/Downloads/8082bece*.zip 
  • We use the -j option to tell unzip not to bother recreating the directory structure of the archive

We want to make sure any shell scripts are executable in the docker container, and remove unecessary files:

cd ~/work/docker/db_setup_scripts
chmod +x *.sh
rm *.md

Run the container

Now we are all prepared, we can tell Docker to run the image, we'll give the container a name as well:

docker run --name oracle -p 1521:1521 -e ORACLE_PDB=ORCL \
           -v ~/work/docker/oradata:/opt/oracle/oradata \
           -v ~/work/docker/db_setup_scripts:/opt/oracle/scripts/setup \
  • The -name argument names the container
  • The -e arguments passed an environment variable that renames the created PDB to ORCL (the default is ORCLPDB1)
  • The first -v argument mounts the folder to store the database data
  • The second -v argument mounts the folder containing the scripts to convert the database to use extended data types

Time for another coffee, creating the initial database takes time. After a while the database will have been created, and the script to enable extended data types will have been executed

Managing the Container

Once the initial setup of the database has completed, I like to stop the container and then start it again to leave it running in the background. To do this, in another terminal do the following:

docker stop oracle
docker start oracle

or simply:

docker restart oracle

Deleting the Container

If you ever need to get rid of the container, then the following will remove the container, you can recreate it again using docker run:

docker stop oracle
docker rm oracle

Connecting to the Database

You can use the sqlplus as described in the docker images documentation but it's a bit hard to use because it can only read from the filesystem within the container. Much better to use it's more modern relative, SQLcl, which will run anywhere you can run Java, and doesn't require an Oracle Client install, so it's super easy to get working, and especially handy for Mac users.

Since we have port forwarded the container's 1521 port to our host's 1521 port, we can use sqlcl to connect to the database as follows:

Connect to the CDB

To Connect to the CDB, just do the following:

sql system

SQLcl: Release RC on Fri Sep 08 18:10:52 2017

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

Password? (**********?) ******
Connected to:
Oracle Database 12c Enterprise Edition Release - 64bit Production


Connect to the PDB

To connect to the PDB, just do the following:

sql system@//localhost:1521/orcl

SQLcl: Release RC on Fri Sep 08 18:12:29 2017

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

Password? (**********?) ******
Connected to:
Oracle Database 12c Enterprise Edition Release - 64bit Production

ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
source oraenv
echo "Enabling extended data types and restarting database in upgrade mode"
sqlplus / as sysdba << EOF
ALTER SYSTEM SET max_string_size=extended SCOPE=SPFILE;
echo "Starting PDB conversion to extended data types"
mkdir /tmp/edt
cd /tmp/edt
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/ -d $ORACLE_HOME/rdbms/admin -b utl32k_output $ORACLE_HOME/rdbms/admin/utl32k.sql
cat *.log
rm -rf /tmp/edt
echo "Completed PDB conversion to extended data types"
echo "Restarting database after enabling extended data types"
sqlplus / as sysdba << EOF
show parameter max_string_size;
echo "Database restarted, extended data types enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.