Just a quick note on how to quickly build a Dockerised local Oracle development database, which contains the Oracle-provided sample schemas and data; i.e. the HR schema and friends. Oracle has for some time provided docker build scripts for a variety of their products on github. Oracle has also provided the samples schema for their databases on github.

Requirements and Assumptions Link to heading

  • You’re running Docker on Windows; tested with Windows 10 Pro and Docker CE via Hyper-V
  • You have installed Ubuntu Bash on Windows; tested with Windows build 15063 running Ubuntu 16.04
  • You have enabled Docker option: Expose Daemon on tcp://localhost:2375 without TLS

Initial Setup Link to heading

Start Ubuntu Bash and run:

sudo apt install docker.io wget
echo 'alias /usr/bin/docker="docker -H=localhost:2375"' >>~/.bash_aliases
exit

Start Ubuntu bash again and run:

mkdir -p ~/dev/git/oracle
cd ~/dev/git/oracle
# Clone Oracle Docker repo
git clone https://github.com/oracle/docker-images.git

Download Oracle Database Files Link to heading

Download the two files linuxamd64_12102_database_se2_1of2.zip and linuxamd64_12102_database_se2_2of2.zip from the page and heading (12.1.0.2.0) - Standard Edition (SE2) and put them in the docker-images/OracleDatabase/dockerfiles/12.1.0.2 repository directory.

Build the Docker Image Link to heading

Now run the following commands from Ubuntu bash to build the docker image:

cd ~/dev/git/oracle/docker-images/OracleDatabase/dockerfiles
# Build docker image for 12.1.0.2 SE2 edition (takes a while)
./buildDockerImage.sh -v 12.1.0.2 -s

docker images

Expected output:

REPOSITORY       TAG            IMAGE ID       CREATED          SIZE
oracle/database  12.1.0.2-se2   dc825c15ed24   28 minutes ago   10.3GB
oraclelinux      7-slim         c0feb50f7527   4 weeks ago      118MB

Create and Run the Database Container Link to heading

Run the next commands to create a running docker container with the database (takes a while):

docker run --name orclcdb_12102se2 -p 1521:1521 -p 5500:5500 \
  -e ORACLE_SID=orclcdb -e ORACLE_PDB=orclpdb1 -e ORACLE_PWD=mysecret42 \
  -e ORACLE_CHARACTERSET=AL32UTF8 oracle/database:12.1.0.2-se2

Install Oracle Sample Schemas Link to heading

Now download and install the Oracle sample schemas:

cd ~/dev/git/oracle/
wget https://github.com/oracle/db-sample-schemas/archive/v12.1.0.2.zip
unzip v12.1.0.2.zip
cd db-sample-schemas-12.1.0.2/
perl -p -i.bak -e 's#__SUB__CWD__#'/opt/oracle/db-sample-schemas-12.1.0.2'#g' *.sql */*.sql */*.dat
cd ..
# This copies the sample schemas inside the container (the alternative would have been to mount a docker volume on container creation/start):
docker cp db-sample-schemas-12.1.0.2/ orclcdb_12102se2:/opt/oracle
# Start a bash shell inside the container
docker exec -t -i orclcdb_12102se2 /bin/bash

Inside the container, run:

cd /opt/oracle/db-sample-schemas-12.1.0.2
mkdir log
sqlplus system/mysecret42@//localhost:1521/orclpdb1

In SQL*Plus, execute:

@mksample mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 users temp /opt/oracle/db-sample-schemas-12.1.0.2/log orclpdb1

Summary Link to heading

And that’s it - the docker container’s Oracle database should now be populated with the Oracle sample schemas and data.

Note that per default a Container database with a Pluggable database is built (even for Standard Edition 2). However, this can be changed to build just a standalone database by editing the ~/dev/git/oracle/docker-images/OracleDatabase/dockerfiles/12.1.0.2/dbca.rsp.tmpl file and changing the option CREATEASCONTAINERDATABASE from true to false. Then re-run buildDockerImage.sh to build a new image.


Originally published at https://jensenmo.blogspot.com/2017/09/building-local-dockerised-oracle-121.html