07 September 2017

Building a local Dockerised Oracle 12.1 SE2 development database with sample schemas and data

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.

  • 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
Start Ubuntu Bash and run:
sudo apt install docker.io wget
echo 'alias /usr/bin/docker="docker -H=localhost:2375"' >>~/.bash_aliases
# 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 the two files linuxamd64_12102_database_se2_1of2.zip and linuxamd64_12102_database_se2_2of2.zip from the page and heading ( - Standard Edition (SE2) and put them in the docker-images/OracleDatabase/dockerfiles/ repository directory. 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 SE2 edition (takes a while)
./buildDockerImage.sh -v -s

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

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:
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-
perl -p -i.bak -e 's#__SUB__CWD__#'/opt/oracle/db-sample-schemas-'#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- orclcdb_12102se2:/opt/oracle
# Start a bash shell inside the container
docker exec -t -i orclcdb_12102se2 /bin/bash
cd /opt/oracle/db-sample-schemas-
mkdir log
sqlplus system/mysecret42@//localhost:1521/orclpdb1
@mksample mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 mysecret42 users temp /opt/oracle/db-sample-schemas- orclpdb1
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/ file and changing the option CREATEASCONTAINERDATABASE from true to false. Then re-run buildDockerImage.sh to build a new image.

No comments: