Permalink
Browse files

Build a development database using a Docker container based on oracle…

…/database:12.1.0.2-ee

The oracle/database:12.1.0.2-ee image can be created by using Oracles script from https://github.com/oracle/docker-images/tree/master/OracleDatabase. Be careful: You need a separate download of the database installation files.

Then use the Maven docker plugin to create and provide a custom DOAG2016 image.

See: https://fabric8io.github.io/docker-maven-plugin/
  • Loading branch information...
michael-simons committed Jul 22, 2016
1 parent 4807ce1 commit 43f32ba516184cc1a9d940e3408b0bd961224a6f
Showing with 85 additions and 4 deletions.
  1. +4 −4 README.md
  2. +32 −0 pom.xml
  3. +40 −0 src/main/scripts/create_tablespace_and_user.sql
  4. +9 −0 src/main/scripts/initdb.sh
View
@@ -22,13 +22,13 @@ As DOAG Konferenz is an Oracle database centric conference, I used Oracle throug
1. Go to [docker.com](http://www.docker.com/products/docker) and install docker on your machine
2. Download [Oracle Database 12c Release 1 Enterprise Edition for Linux](http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-linux-download-2240591.html)
-3. Go to [Oracles docker images repository](https://github.com/oracle/docker-images/tree/master/OracleDatabase), download the _OracleDatabase_ scripts and follow the instructions. Remember to add the two files from step 2 to "dockerfiles/12.1.0.2". I used the following command: `./buildDockerImage.sh -v 12.1.0.2 -e -p admin`
-4. Then, inside this repository use `docker build -t msimons/doag2016 .` to create an image containing a user _doag2016_ with the same password inside the PDB container _ORCLPDB1_
-5. Run a container based on this image with `docker run -d -p 1521:1521 -p 5500:5500 -p 5501:5501 msimons/doag2016`
+3. Go to [Oracles docker images repository](https://github.com/oracle/docker-images/tree/master/OracleDatabase), download the _OracleDatabase_ scripts and follow the instructions. Remember to add the two files from step 2 to "dockerfiles/12.1.0.2". I used the following command: `./buildDockerImage.sh -v 12.1.0.2 -e`
+4. Then, inside this repository, create a running container of this image with `mvn docker:start`. The first start will take a while. The reason behind this is that the Oracle database files are created during the first start and not during image creation. The files are storted inside `${project.basedir}/var`. There's a timeout of 30 minutes. You may have to change this if you are on a slower machine
+5. The container exposes the following ports to localhost: 1521, 5500 and 5501. The first for SQL*Plus, the later ones for the Oracle Enterprise Manager
You can access the Enterprise manager express for the root container at [https://localhost:5500/em](https://localhost:5500/em) and the container ORCLPDB1 at [https://localhost:5501/em](https://localhost:5501/em).
-Use SQL*Plus to interact with the database. The admin password depends on what you used in step 3, the _doag2016_ account can be used with `sqlplus doag2016/doag2016@//localhost:1521/ORCLPDB1`.
+Use SQL*Plus to interact with the database. The admin password is a password generated during first startup and you can find it inside the container logs. The _doag2016_ account can be used with `sqlplus doag2016/doag2016@//localhost:1521/ORCLPDB1`, the password is _doag2016_, too.
View
32 pom.xml
@@ -57,6 +57,38 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>0.17.1</version>
+ <configuration>
+ <images>
+ <image>
+ <name>oracle/database:12.1.0.2-ee</name>
+ <run>
+ <volumes>
+ <bind>
+ <volume>${project.build.scriptSourceDirectory}:/var/tmp/scripts</volume>
+ <volume>${basedir}/var/oradata:/opt/oracle/oradata</volume>
+ </bind>
+ </volumes>
+ <ports>
+ <port>1521:1521</port>
+ <port>5500:5500</port>
+ <port>5501:5501</port>
+ </ports>
+ <wait>
+ <log>DATABASE IS READY TO USE!</log>
+ <time>3600000</time>
+ <exec>
+ <postStart>/var/tmp/scripts/initdb.sh</postStart>
+ </exec>
+ </wait>
+ </run>
+ </image>
+ </images>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -0,0 +1,40 @@
+-- Change to PDB which was created inside parent iamge
+ALTER SESSION SET CONTAINER = ORCLPDB1;
+
+-- Enable Enterprise Manager Express on port 5501
+EXEC dbms_xdb_config.sethttpsport(5501);
+
+-- Create table space for demo application
+DECLARE
+ v_ts_id V$TABLESPACE.TS#%TYPE;
+BEGIN
+ SELECT TS# into v_ts_id FROM V$TABLESPACE WHERE name = 'DOAG2016';
+EXCEPTION
+ WHEN no_data_found THEN
+ EXECUTE IMMEDIATE
+ 'CREATE SMALLFILE TABLESPACE "DOAG2016" ' ||
+ ' DATAFILE ''/opt/oracle/oradata/ORCLCDB/ORCLPDB1/doag2016-1.dbf'' SIZE 512M AUTOEXTEND ON NEXT 128M MAXSIZE 1024M ' ||
+ ' LOGGING ' ||
+ ' DEFAULT NOCOMPRESS ' ||
+ ' ONLINE ' ||
+ ' EXTENT MANAGEMENT LOCAL AUTOALLOCATE ' ||
+ ' SEGMENT SPACE MANAGEMENT AUTO';
+END;
+/
+
+-- Create doag2016 user
+DECLARE
+ v_id DBA_USERS.USER_ID%TYPE;
+BEGIN
+ SELECT USER_ID INTO v_id FROM DBA_USERS WHERE username = 'DOAG2016';
+EXCEPTION
+ WHEN no_data_found THEN
+ EXECUTE IMMEDIATE
+ 'CREATE USER doag2016 IDENTIFIED BY doag2016 PROFILE "DEFAULT" ACCOUNT UNLOCK DEFAULT TABLESPACE "DOAG2016" TEMPORARY TABLESPACE "TEMP"';
+END;
+/
+
+GRANT "CONNECT" TO doag2016;
+GRANT "DBA" TO doag2016;
+
+EXIT;
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+echo 'Initialising database'
+
+export ORACLE_SID=ORCLCDB
+
+sqlplus / as sysdba @/var/tmp/scripts/create_tablespace_and_user.sql
+
+echo 'Tablespace and user created'

0 comments on commit 43f32ba

Please sign in to comment.