├── .gitignore ├── Dockerfile ├── README.md └── entrypoint.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM absolutapps/oracle-12c-ee-base 2 | 3 | ENV INIT_MEM_PST 40 4 | ENV SW_ONLY false 5 | ENV TERM dumb 6 | 7 | ADD entrypoint.sh /entrypoint.sh 8 | 9 | EXPOSE 1521 10 | EXPOSE 8080 11 | EXPOSE 5500 12 | 13 | VOLUME ["/u01/app/oracle"] 14 | 15 | ENTRYPOINT ["/entrypoint.sh"] 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Oracle 12c EE image 2 | Image provides "Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production" with Enterprise Manager Lite console enabled. 3 | For those who are suffering from SQLPLUS inability to provide history using keyboard arrows "rlwrap" utility has been incorporated as well 4 | 5 | ### Running image 6 | ```sh 7 | $ docker run -d --name oracle --privileged absolutapps/oracle-12c-ee 8 | ``` 9 | This will create a default database and run oracle inside docker container. 10 | Oracle should be run in “privileged” mode as oracle requires special ports and kernel settings to be enabled 11 | However in real environment it's better to use more comprehensive statement useful for real life: 12 | ```sh 13 | $ docker run -d --name oracle \ 14 | --privileged -v $(pwd)/oradata:/u01/app/oracle \ 15 | -p 8080:8080 -p 1521:1521 absolutapps/oracle-12c-ee 16 | ``` 17 | In this case database settings and data will be saved to $(pwd)/oradata folder and ports will be exposed either to localhost or boot2docker container (MacOs and Win). 18 | 19 | ### Additional options 20 | - `ORACLE_SID` - Oracle SID (default to ORCL) 21 | - `SERVICE_NAME` - $ORACLE_SID 22 | - Listener port - 1521 23 | - EM port - 8080 24 | - SYS, SYSTEM passwords: oracle 25 | - Amount of memory 40% `INIT_MEM_PST` 26 | 27 | ### Running scripts at startup 28 | Shell scripts (sh) and sql scripts (sql) placed in `/oracle.init.d/`directory will be executed after database creation (or start). 29 | Please note that sql scripts are executed under SYS user account, so in order to execute sql under different account construction like “connect user/password” should be used at the beginning of the script. 30 | Shell scripts are executed as root. Please use “gosu” instead of “su - ” to run script under different account. 31 | (More about “gosu” advantages can be found here https://github.com/tianon/gosu/) 32 | 33 | ### Using rlwrap 34 | This utility allows user to use history in sqlplus in the same way as with MySQL. Just use "rlwrap sqlplus" instead of "sqlplus" 35 | 36 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | sysctl -p > /dev/null 2>&1 || true 5 | 6 | chown -R oracle:oinstall $ORACLE_BASE 7 | chown -R oracle:oinstall /u01/app/oracle-product 8 | rm -fr $ORACLE_BASE/product 9 | ln -s /u01/app/oracle-product $ORACLE_BASE/product 10 | 11 | /u01/app/oraInventory/orainstRoot.sh > /dev/null 2>&1 12 | echo | $ORACLE_BASE/product/12.1.0.2/dbhome_1/root.sh > /dev/null 2>&1 || true 13 | 14 | start_listener(){ 15 | gosu oracle echo "LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $(hostname))(PORT = 1521))))" > $ORACLE_HOME/network/admin/listener.ora 16 | gosu oracle echo "" > $ORACLE_HOME/network/admin/sqlnet.ora 17 | gosu oracle lsnrctl start 18 | } 19 | 20 | reload_listener(){ 21 | gosu oracle lsnrctl reload 22 | } 23 | 24 | create_database(){ 25 | gosu oracle dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ${ORACLE_SID} -sid ${ORACLE_SID} -responseFile NO_VALUE -characterSet AL32UTF8 -emConfiguration LOCAL -automaticMemoryManagement false -memoryPercentage $INIT_MEM_PST -redoLogFileSize 100 -recoveryAreaDestination NONE -databaseType MULTIPURPOSE -pdbAdminPassword oracle -sysPassword oracle -systemPassword oracle 26 | } 27 | 28 | start_database(){ 29 | gosu oracle sqlplus -silent /nolog << EOF 30 | connect sys/oracle as sysdba; 31 | startup; 32 | exit; 33 | EOF 34 | } 35 | 36 | shutdown_database(){ 37 | if [ "$SW_ONLY" != "true" ]; then 38 | gosu oracle sqlplus -silent /nolog << EOF 39 | connect sys/oracle as sysdba; 40 | shutdown immediate; 41 | exit; 42 | EOF 43 | fi 44 | } 45 | 46 | set_http_port(){ 47 | gosu oracle sqlplus -silent /nolog << EOF 48 | connect sys/oracle as sysdba; 49 | EXEC DBMS_XDB.sethttpport(8080); 50 | exit; 51 | EOF 52 | } 53 | 54 | _run_script(){ 55 | gosu oracle sqlplus -silent /nolog << EOF 56 | connect sys/oracle as sysdba; 57 | @$1 58 | exit; 59 | EOF 60 | } 61 | 62 | 63 | run_init_scripts(){ 64 | exec="Init scripts in /oracle.init.d/" 65 | for f in /oracle.init.d/*; do 66 | case "$f" in 67 | *.sh) echo "$exec: Running $f"; . "$f" || true ;; 68 | *.sql) echo "$exec: Running $f"; _run_script "$f" || true ; echo ;; 69 | *) echo "$exec: Ignoring $f" ;; 70 | esac 71 | echo 72 | done 73 | } 74 | 75 | case "$1" in 76 | '') 77 | if [ "$SW_ONLY" == "true" ]; then 78 | echo "Software only mode, nothing has been installed, enviroment is ready" 79 | echo "Init scripts nevertheless will be run" 80 | echo "Oracle home is: ${ORACLE_HOME}" 81 | echo "Oracle base is: ${ORACLE_BASE}" 82 | else 83 | if [ "$(ls -A $ORACLE_BASE/oradata/$ORACLE_SID)" ]; then 84 | echo "Found database files in $ORACLE_BASE/oradata/$ORACLE_SID. Trying to start database" 85 | echo "Restoring configuration from $ORACLE_BASE/dbs" 86 | echo "$ORACLE_SID:$ORACLE_HOME:N" > /etc/oratab 87 | chown oracle:oinstall /etc/oratab 88 | chown 664 /etc/oratab 89 | rm -rf $ORACLE_HOME/dbs 90 | ln -s $ORACLE_BASE/dbs $ORACLE_HOME/dbs 91 | start_listener 92 | start_database 93 | else 94 | echo "No databases found in $ORACLE_BASE/oradata/$ORACLE_SID. About to create a new database instance" 95 | # preserving oracle configuratioin for future run 96 | mv $ORACLE_HOME/dbs $ORACLE_BASE/dbs 97 | ln -s $ORACLE_BASE/dbs $ORACLE_HOME/dbs 98 | echo "Starting database listener" 99 | start_listener 100 | create_database 101 | reload_listener 102 | echo "Database has been created in $ORACLE_BASE/oradata/$ORACLE_SID" 103 | echo "SYS and SYSTEM passwords are set to [oracle]" 104 | fi 105 | echo "Setting HTTP port to 8080" 106 | set_http_port 107 | echo "Please login to http://:8080/em to use enterprise manager" 108 | echo "User: sys; Password oracle; Sysdba: true" 109 | fi 110 | 111 | echo "Fixing permissions..." 112 | chown -R oracle:oinstall /u01 113 | 114 | echo "Running init scripts..." 115 | run_init_scripts 116 | echo "Done with scripts we are ready to go" 117 | 118 | while [ "$END" == '' ]; do 119 | sleep 1 120 | trap "shutdown_database" INT TERM 121 | done 122 | ;; 123 | 124 | *) 125 | echo "Nothing has been configured. Please run '/entrypoint.sh' to install or start db" 126 | $1 127 | ;; 128 | esac 129 | 130 | --------------------------------------------------------------------------------